Skip to content

Commit

Permalink
Add feature rkyv that derives the traits from the rkyv crate for …
Browse files Browse the repository at this point in the history
…`Primes<N>` (#66)

* Add feature `rklyv` that derives the traits from the `rkyv` crate for `Primes`. Removes the impl of the comparison and ordering traits, as all instances of the type are the same.

* cargo fmt

* Add `rkyv` feature docs

* cargo fmt

* Add test of zerocopy::AsBytes impl
  • Loading branch information
JSorngard authored Sep 12, 2024
1 parent 927324c commit ff3159d
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 98 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ This file contains the changes to the crate since version 0.4.8.
from `core`. The crate is thus always `no_std` compatible.
If the `serde` feature is enabled the crate uses the [`serde_arrays`](https://crates.io/crates/serde_arrays)
crate to serialize the type, and that crate in turn uses the standard library.
- Removed the implementations of `PartialEq`, `Eq`, `PartialOrd`, and `Ord` from
`Primes`. To perform comparisons of the numbers in the struct with arrays or
slices you can call `as_array` or `as_slice`. The reson for the removal is that
every instance of `Primes<N>` for a given `N` is the same, which means that
comparisons and orderings are pointless, since `N` is part of the type signature.

These changes mean that the MSRV of the crate is increased from 1.67.1 to 1.81.0.

### Other changes

- Added the `zerocopy` feature that derives the `AsBytes` trait from the [`zerocopy`](https://crates.io/crates/zerocopy)
crate for the `Primes<N>` struct.
- Added the `rkyv` feature that derives the `Serialize`, `Deserialize`, and `Archive`
traits from the [`rkyv`](https://crates.io/crates/rkyv) crate for the `Primes<N>`
struct.

## 0.8.7

Expand Down
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ repository = "https://github.com/JSorngard/const-primes/"
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
serde_arrays = { version = "0.1.0", optional = true }
zerocopy = { version = "0.7", default-features = false, features = ["derive"], optional = true }
rkyv = { version = "0.8.1", default-features = false, optional = true }

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
rand = { version = "0.8", default-features = false, features = ["small_rng"] }

[features]
# Derives the `Serialize` and `Deserialize` traits from [`serde`](https://crates.io/crates/serde) for the `Primes` struct, as well as a few others.
# Derives the `Serialize` and `Deserialize` traits from the [`serde`](https://crates.io/crates/serde) crate for the `Primes` struct, as well as a few others.
# Uses the [`serde_arrays`](https://crates.io/crates/serde_arrays) crate to do this, and that crate uses the standard library.
serde = ["dep:serde", "dep:serde_arrays"]

# Derives the `AsBytes` trait from the [`zerocopy`](https://crates.io/crates/zerocopy) crate for the `Primes` struct.
zerocopy = ["dep:zerocopy"]

# Derives the `Serialize`, `Deserialize`, and `Archive` traits from the [`rkyv`](https://crates.io/crates/rkyv) crate for the `Primes` struct.
rkyv = ["dep:rkyv"]

[package.metadata.docs.rs]
# Document all features.
all-features = true
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ crate to do this, and that crate uses the standard library.
`zerocopy`: derives the `AsBytes` trait from [`zerocopy`](https://crates.io/crates/zerocopy)
for the `Primes` struct.

`rkyv`: derives the `Serialize`, `Deserialize`, and `Archive` traits from the
[`rkyv`](https://crates.io/crates/rkyv) crate for the [`Primes`] struct.

## License

Licensed under either of
Expand Down
Loading

0 comments on commit ff3159d

Please sign in to comment.