diff --git a/Cargo.toml b/Cargo.toml index 907442cf..90869f44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 1b598952..63fbd0ce 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -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 Archive for Matrix { type Archived = Matrix; @@ -325,6 +326,22 @@ mod rkyv_impl { }) } } + + impl<__C: ?Sized, T, R, C, S: CheckBytes<__C>> + CheckBytes<__C> + for Matrix + where + S: CheckBytes<__C>, + { + type Error = >::Error; + unsafe fn check_bytes<'a>( + value: *const Matrix, + context: &mut __C, + ) -> Result<&'a Self, Self::Error> { + let _ = S::check_bytes(::core::ptr::addr_of!((*value).data), context)?; + Ok(&*value) + } + } } impl Matrix {