Merge pull request #831 from iMplode-nZ/dev

Added bytemuck implementations for static storages.
This commit is contained in:
Sébastien Crozet 2021-02-25 15:46:28 +01:00 committed by GitHub
commit 69e2ad6a44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 1 deletions

View File

@ -40,7 +40,6 @@ proptest-support = [ "proptest" ]
# This feature is only used for tests, and enables tests that require more time to run # This feature is only used for tests, and enables tests that require more time to run
slow-tests = [] slow-tests = []
[dependencies] [dependencies]
typenum = "1.12" typenum = "1.12"
generic-array = "0.14" generic-array = "0.14"
@ -59,6 +58,7 @@ mint = { version = "0.5", optional = true }
quickcheck = { version = "0.9", optional = true } quickcheck = { version = "0.9", optional = true }
pest = { version = "2", optional = true } pest = { version = "2", optional = true }
pest_derive = { version = "2", optional = true } pest_derive = { version = "2", optional = true }
bytemuck = { version = "1.5", optional = true }
matrixcompare-core = { version = "0.1", optional = true } matrixcompare-core = { version = "0.1", optional = true }
proptest = { version = "0.10", optional = true, default-features = false, features = ["std"] } proptest = { version = "0.10", optional = true, default-features = false, features = ["std"] }

View File

@ -394,6 +394,26 @@ where
} }
} }
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar + bytemuck::Zeroable, R: DimName, C: DimName> bytemuck::Zeroable
for ArrayStorage<N, R, C>
where
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
Self: Copy,
{
}
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar + bytemuck::Pod, R: DimName, C: DimName> bytemuck::Pod
for ArrayStorage<N, R, C>
where
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
Self: Copy,
{
}
#[cfg(feature = "abomonation-serialize")] #[cfg(feature = "abomonation-serialize")]
impl<N, R, C> Abomonation for ArrayStorage<N, R, C> impl<N, R, C> Abomonation for ArrayStorage<N, R, C>
where where

View File

@ -279,6 +279,22 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> matrixcompare_core::DenseAc
} }
} }
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> bytemuck::Zeroable
for Matrix<N, R, C, S>
where
S: bytemuck::Zeroable,
{
}
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> bytemuck::Pod for Matrix<N, R, C, S>
where
S: bytemuck::Pod,
Self: Copy,
{
}
impl<N: Scalar, R: Dim, C: Dim, S> Matrix<N, R, C, S> { impl<N: Scalar, R: Dim, C: Dim, S> Matrix<N, R, C, S> {
/// Creates a new matrix with the given data without statically checking that the matrix /// Creates a new matrix with the given data without statically checking that the matrix
/// dimension matches the storage dimension. /// dimension matches the storage dimension.

View File

@ -30,6 +30,12 @@ pub struct Unit<T> {
pub(crate) value: T, pub(crate) value: T,
} }
#[cfg(feature = "bytemuck")]
unsafe impl<T> bytemuck::Zeroable for Unit<T> where T: bytemuck::Zeroable {}
#[cfg(feature = "bytemuck")]
unsafe impl<T> bytemuck::Pod for Unit<T> where T: bytemuck::Pod {}
#[cfg(feature = "serde-serialize")] #[cfg(feature = "serde-serialize")]
impl<T: Serialize> Serialize for Unit<T> { impl<T: Serialize> Serialize for Unit<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>

View File

@ -65,6 +65,24 @@ where
{ {
} }
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar, D: DimName> bytemuck::Zeroable for Point<N, D>
where
VectorN<N, D>: bytemuck::Zeroable,
DefaultAllocator: Allocator<N, D>,
{
}
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar, D: DimName> bytemuck::Pod for Point<N, D>
where
N: Copy,
VectorN<N, D>: bytemuck::Pod,
DefaultAllocator: Allocator<N, D>,
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
{
}
#[cfg(feature = "serde-serialize")] #[cfg(feature = "serde-serialize")]
impl<N: Scalar, D: DimName> Serialize for Point<N, D> impl<N: Scalar, D: DimName> Serialize for Point<N, D>
where where

View File

@ -40,6 +40,17 @@ impl<N: Scalar + Zero> Default for Quaternion<N> {
} }
} }
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar> bytemuck::Zeroable for Quaternion<N> where Vector4<N>: bytemuck::Zeroable {}
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar> bytemuck::Pod for Quaternion<N>
where
Vector4<N>: bytemuck::Pod,
N: Copy,
{
}
#[cfg(feature = "abomonation-serialize")] #[cfg(feature = "abomonation-serialize")]
impl<N: Scalar> Abomonation for Quaternion<N> impl<N: Scalar> Abomonation for Quaternion<N>
where where