Skip to content

Commit

Permalink
Add zerocopy feature that derives zerocopy::AsBytes for Primes<N>.
Browse files Browse the repository at this point in the history
  • Loading branch information
JSorngard committed Sep 12, 2024
1 parent 96fdadc commit 04e57f2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ This file contains the changes to the crate since version 0.4.8.

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.

## 0.8.7

- Sped up `is_prime` by checking fewer witnesses in the Miller-Rabin test.
Expand Down
21 changes: 21 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = "https://github.com/JSorngard/const-primes/"
[dependencies]
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 }

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
Expand All @@ -22,6 +23,9 @@ rand = { version = "0.8", default-features = false, features = ["small_rng"] }
# 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"]

[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 @@ -122,6 +122,9 @@ 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.

`zerocopy`: derives the `AsBytes` trait from [`zerocopy`](https://crates.io/crates/zerocopy)
for the `Primes` struct.

## License

Licensed under either of
Expand Down
2 changes: 2 additions & 0 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use serde::{Deserialize, Serialize};
/// ```
#[derive(Debug, Clone, Copy, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "zerocopy", derive(zerocopy::AsBytes))]
#[repr(transparent)]
pub struct Primes<const N: usize>(
#[cfg_attr(feature = "serde", serde(with = "serde_arrays"))] [Underlying; N],
);
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@
//!
//! # Features
//!
//! `serde`: derives the [`Serialize`](serde::Serialize) and [`Deserialize`](serde::Deserialize) traits from [`serde`](https://docs.rs/serde/latest/serde/) for the [`Primes`] struct, as well as a few others.
//! `serde`: derives the [`Serialize`](serde::Serialize) and [`Deserialize`](serde::Deserialize) traits from [`serde`] for the [`Primes`] struct, as well as a few others.
//! Uses the [`serde_arrays`](https://docs.rs/serde_arrays/0.1.0) crate to do this, and that crate uses the standard library.
//!
//! `zerocopy`: derives the [`AsBytes`](zerocopy::AsBytes) trait from [`zerocopy`] for the [`Primes`] struct.

#![forbid(unsafe_code)]
#![no_std]
Expand Down

0 comments on commit 04e57f2

Please sign in to comment.