forked from M-Labs/nalgebra
add bytecheck for matrix
This commit is contained in:
parent
8c36ab4ceb
commit
7b5fb956d0
@ -52,7 +52,7 @@ convert-glam020 = [ "glam020" ]
|
||||
## `serde-serialize`.
|
||||
serde-serialize-no-std = [ "serde", "num-complex/serde" ]
|
||||
serde-serialize = [ "serde-serialize-no-std", "serde/std" ]
|
||||
rkyv-serialize-no-std = [ "rkyv" ]
|
||||
rkyv-serialize-no-std = [ "rkyv", "bytecheck" ]
|
||||
rkyv-serialize = [ "rkyv-serialize-no-std", "rkyv/std" ]
|
||||
|
||||
# Randomness
|
||||
@ -80,6 +80,7 @@ rand_distr = { version = "0.4", default-features = false, optional = true }
|
||||
matrixmultiply = { version = "0.3", optional = true }
|
||||
serde = { version = "1.0", default-features = false, features = [ "derive" ], optional = true }
|
||||
rkyv = { version = "~0.7.1", optional = true }
|
||||
bytecheck = { version = "~0.6.1", optional = true }
|
||||
mint = { version = "0.5", optional = true }
|
||||
quickcheck = { version = "1", optional = true }
|
||||
pest = { version = "2", optional = true }
|
||||
|
@ -293,6 +293,7 @@ mod rkyv_impl {
|
||||
use super::Matrix;
|
||||
use core::marker::PhantomData;
|
||||
use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize};
|
||||
use bytecheck::CheckBytes;
|
||||
|
||||
impl<T: Archive, R: Archive, C: Archive, S: Archive> Archive for Matrix<T, R, C, S> {
|
||||
type Archived = Matrix<T::Archived, R::Archived, C::Archived, S::Archived>;
|
||||
@ -325,6 +326,22 @@ mod rkyv_impl {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<__C: ?Sized, T, R, C, S: CheckBytes<__C>>
|
||||
CheckBytes<__C>
|
||||
for Matrix<T, R, C, S>
|
||||
where
|
||||
S: CheckBytes<__C>,
|
||||
{
|
||||
type Error = <S as CheckBytes<__C>>::Error;
|
||||
unsafe fn check_bytes<'a>(
|
||||
value: *const Matrix<T, R, C, S>,
|
||||
context: &mut __C,
|
||||
) -> Result<&'a Self, Self::Error> {
|
||||
let _ = S::check_bytes(::core::ptr::addr_of!((*value).data), context)?;
|
||||
Ok(&*value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, R, C, S> Matrix<T, R, C, S> {
|
||||
|
Loading…
Reference in New Issue
Block a user