Skip to content

Commit 04e57f2

Browse files
committed
Add zerocopy feature that derives zerocopy::AsBytes for Primes<N>.
1 parent 96fdadc commit 04e57f2

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ This file contains the changes to the crate since version 0.4.8.
1414

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

17+
### Other changes
18+
19+
- Added the `zerocopy` feature that derives the `AsBytes` trait from the [`zerocopy`](https://crates.io/crates/zerocopy)
20+
crate for the `Primes<N>` struct.
21+
1722
## 0.8.7
1823

1924
- Sped up `is_prime` by checking fewer witnesses in the Miller-Rabin test.

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repository = "https://github.com/JSorngard/const-primes/"
1212
[dependencies]
1313
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
1414
serde_arrays = { version = "0.1.0", optional = true }
15+
zerocopy = { version = "0.7", default-features = false, features = ["derive"], optional = true }
1516

1617
[dev-dependencies]
1718
criterion = { version = "0.5", features = ["html_reports"] }
@@ -22,6 +23,9 @@ rand = { version = "0.8", default-features = false, features = ["small_rng"] }
2223
# Uses the [`serde_arrays`](https://crates.io/crates/serde_arrays) crate to do this, and that crate uses the standard library.
2324
serde = ["dep:serde", "dep:serde_arrays"]
2425

26+
# Derives the `AsBytes` trait from the [`zerocopy`](https://crates.io/crates/zerocopy) crate for the `Primes` struct.
27+
zerocopy = ["dep:zerocopy"]
28+
2529
[package.metadata.docs.rs]
2630
# Document all features.
2731
all-features = true

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ for the `Primes` struct, as well as a few others.
122122
Uses the [`serde_arrays`](https://crates.io/crates/serde_arrays)
123123
crate to do this, and that crate uses the standard library.
124124

125+
`zerocopy`: derives the `AsBytes` trait from [`zerocopy`](https://crates.io/crates/zerocopy)
126+
for the `Primes` struct.
127+
125128
## License
126129

127130
Licensed under either of

src/cache/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ use serde::{Deserialize, Serialize};
4545
/// ```
4646
#[derive(Debug, Clone, Copy, Eq, Ord, Hash)]
4747
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
48+
#[cfg_attr(feature = "zerocopy", derive(zerocopy::AsBytes))]
49+
#[repr(transparent)]
4850
pub struct Primes<const N: usize>(
4951
#[cfg_attr(feature = "serde", serde(with = "serde_arrays"))] [Underlying; N],
5052
);

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@
105105
//!
106106
//! # Features
107107
//!
108-
//! `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.
108+
//! `serde`: derives the [`Serialize`](serde::Serialize) and [`Deserialize`](serde::Deserialize) traits from [`serde`] for the [`Primes`] struct, as well as a few others.
109109
//! Uses the [`serde_arrays`](https://docs.rs/serde_arrays/0.1.0) crate to do this, and that crate uses the standard library.
110+
//!
111+
//! `zerocopy`: derives the [`AsBytes`](zerocopy::AsBytes) trait from [`zerocopy`] for the [`Primes`] struct.
110112
111113
#![forbid(unsafe_code)]
112114
#![no_std]

0 commit comments

Comments
 (0)