diff --git a/Cargo.toml b/Cargo.toml index 8dabac1..3664b71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,16 +35,27 @@ default = [ "serde", "std", ] +## Implements traits from [`approx`](https://crates.io/crates/approx) for `Constrained` types. +approx = [ + "dep:approx", +] +## Derives `Pod` & `Zeroable` traits from [`bytemuck`](https://crates.io/crates/bytemuck) for `Constrained` types. +bytemuck = [ + "dep:bytemuck", +] +## Enable support for [`serde`](https://crates.io/crates/serde) for `Constrained` types. serde = [ "dep:serde", "dep:serde_derive", ] +## Integrates the `std` library and enables dependent features. std = [ "approx/std", "num-traits/std", "serde/std", "thiserror/std", ] +## Enables features that require an unstable (`nighty`) compiler. unstable = [] [dependencies.approx] @@ -53,6 +64,14 @@ default-features = false features = [] optional = true +[dependencies.bytemuck] +version = "^1.22" +features = ["derive"] +optional = true + +[dependencies.document-features] +version = "0.2" + [dependencies.num-traits] version = "^0.2.0" default-features = false diff --git a/src/lib.rs b/src/lib.rs index c19e6de..5b4c510 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,7 +121,9 @@ //! [`Constraint`]: crate::constraint::Constraint //! [`Expression`]: crate::expression::Expression //! [`Try`]: core::ops::Try - +//! +//! # Feature flags +#![doc = document_features::document_features!()] #![doc( html_favicon_url = "https://raw.githubusercontent.com/olson-sean-k/decorum/master/doc/decorum-favicon.ico" )] diff --git a/src/proxy/constrained.rs b/src/proxy/constrained.rs index 60c22e6..2131524 100644 --- a/src/proxy/constrained.rs +++ b/src/proxy/constrained.rs @@ -85,6 +85,25 @@ pub struct Constrained { phantom: PhantomData C>, } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Constrained +where + Constrained: Copy + Clone, + T: bytemuck::Zeroable + 'static, + C: 'static, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Constrained { + fn zeroed() -> Self { + Constrained { + inner: bytemuck::Zeroable::zeroed(), + phantom: PhantomData, + } + } +} + impl Constrained { pub(crate) const fn unchecked(inner: T) -> Self { Constrained {