diff --git a/Cargo.toml b/Cargo.toml index 314f5174..afc103db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,6 @@ proptest-support = [ "proptest" ] # This feature is only used for tests, and enables tests that require more time to run slow-tests = [] - [dependencies] typenum = "1.12" generic-array = "0.14" @@ -59,6 +58,7 @@ mint = { version = "0.5", optional = true } quickcheck = { version = "0.9", optional = true } pest = { version = "2", optional = true } pest_derive = { version = "2", optional = true } +bytemuck = { version = "1.5", optional = true } matrixcompare-core = { version = "0.1", optional = true } proptest = { version = "0.10", optional = true, default-features = false, features = ["std"] } diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index 4fdd3e73..e067cb49 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -394,6 +394,26 @@ where } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable + for ArrayStorage +where + R::Value: Mul, + Prod: ArrayLength, + Self: Copy, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod + for ArrayStorage +where + R::Value: Mul, + Prod: ArrayLength, + Self: Copy, +{ +} + #[cfg(feature = "abomonation-serialize")] impl Abomonation for ArrayStorage where diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 8035d2f8..eb525b14 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -279,6 +279,22 @@ impl> matrixcompare_core::DenseAc } } +#[cfg(feature = "bytemuck")] +unsafe impl> bytemuck::Zeroable + for Matrix +where + S: bytemuck::Zeroable, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl> bytemuck::Pod for Matrix +where + S: bytemuck::Pod, + Self: Copy, +{ +} + impl Matrix { /// Creates a new matrix with the given data without statically checking that the matrix /// dimension matches the storage dimension. diff --git a/src/base/unit.rs b/src/base/unit.rs index 2483307a..70e3a927 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -30,6 +30,12 @@ pub struct Unit { pub(crate) value: T, } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Unit where T: bytemuck::Zeroable {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Unit where T: bytemuck::Pod {} + #[cfg(feature = "serde-serialize")] impl Serialize for Unit { fn serialize(&self, serializer: S) -> Result diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 75410ccd..390db80b 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -65,6 +65,24 @@ where { } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Point +where + VectorN: bytemuck::Zeroable, + DefaultAllocator: Allocator, +{ +} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Point +where + N: Copy, + VectorN: bytemuck::Pod, + DefaultAllocator: Allocator, + >::Buffer: Copy, +{ +} + #[cfg(feature = "serde-serialize")] impl Serialize for Point where diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index a56b69c3..172f2e66 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -40,6 +40,17 @@ impl Default for Quaternion { } } +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Quaternion where Vector4: bytemuck::Zeroable {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Pod for Quaternion +where + Vector4: bytemuck::Pod, + N: Copy, +{ +} + #[cfg(feature = "abomonation-serialize")] impl Abomonation for Quaternion where