Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)]
Expand Down
19 changes: 19 additions & 0 deletions src/proxy/constrained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ pub struct Constrained<T, C> {
phantom: PhantomData<fn() -> C>,
}

#[cfg(feature = "bytemuck")]
unsafe impl<T, C> bytemuck::Pod for Constrained<T, C>
where
Constrained<T, C>: Copy + Clone,
T: bytemuck::Zeroable + 'static,
C: 'static,
{
}

#[cfg(feature = "bytemuck")]
unsafe impl<T: bytemuck::Zeroable, C> bytemuck::Zeroable for Constrained<T, C> {
fn zeroed() -> Self {
Constrained {
inner: bytemuck::Zeroable::zeroed(),
phantom: PhantomData,
}
}
}

impl<T, C> Constrained<T, C> {
pub(crate) const fn unchecked(inner: T) -> Self {
Constrained {
Expand Down