From 90f2603de4790f7ac3a13096eae4e1cb3db9d7d4 Mon Sep 17 00:00:00 2001 From: zyansheep Date: Mon, 21 Mar 2022 12:08:46 -0400 Subject: [PATCH 1/5] upgrade rkyv to 0.7 --- Cargo.toml | 2 +- src/base/array_storage.rs | 16 ++++------------ src/base/dimension.rs | 8 +------- src/base/matrix.rs | 16 ++++------------ src/base/unit.rs | 16 ++++------------ src/geometry/isometry.rs | 23 ++++++----------------- src/geometry/quaternion.rs | 16 ++++------------ src/geometry/scale.rs | 16 ++++------------ src/geometry/translation.rs | 16 ++++------------ 9 files changed, 32 insertions(+), 97 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a629b554..907442cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,7 +79,7 @@ alga = { version = "0.9", default-features = false, optional = true } 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.6.4", default-features = false, features = ["const_generics"], optional = true } +rkyv = { version = "~0.7.1", optional = true } mint = { version = "0.5", optional = true } quickcheck = { version = "1", optional = true } pest = { version = "2", optional = true } diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index b6bd236a..d6dab40a 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -277,23 +277,15 @@ unsafe impl by #[cfg(feature = "rkyv-serialize-no-std")] mod rkyv_impl { use super::ArrayStorage; - use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize}; + use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; impl Archive for ArrayStorage { type Archived = ArrayStorage; type Resolver = <[[T; R]; C] as Archive>::Resolver; - fn resolve( - &self, - pos: usize, - resolver: Self::Resolver, - out: &mut core::mem::MaybeUninit, - ) { - self.0.resolve( - pos + offset_of!(Self::Archived, 0), - resolver, - project_struct!(out: Self::Archived => 0), - ); + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + let (fp, fo) = out_field!(out.0); + self.0.resolve(pos + fp, resolver, fo); } } diff --git a/src/base/dimension.rs b/src/base/dimension.rs index de51339f..39e0459d 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -242,13 +242,7 @@ mod rkyv_impl { type Archived = Self; type Resolver = (); - fn resolve( - &self, - _: usize, - _: Self::Resolver, - _: &mut core::mem::MaybeUninit, - ) { - } + unsafe fn resolve(&self, _: usize, _: Self::Resolver, _: *mut Self::Archived) {} } impl Serialize for Const { diff --git a/src/base/matrix.rs b/src/base/matrix.rs index f12cb3fa..1b598952 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -292,23 +292,15 @@ where mod rkyv_impl { use super::Matrix; use core::marker::PhantomData; - use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize}; + use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; impl Archive for Matrix { type Archived = Matrix; type Resolver = S::Resolver; - fn resolve( - &self, - pos: usize, - resolver: Self::Resolver, - out: &mut core::mem::MaybeUninit, - ) { - self.data.resolve( - pos + offset_of!(Self::Archived, data), - resolver, - project_struct!(out: Self::Archived => data), - ); + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + let (fp, fo) = out_field!(out.data); + self.data.resolve(pos + fp, resolver, fo); } } diff --git a/src/base/unit.rs b/src/base/unit.rs index bb8b56a1..d82c67ec 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -61,23 +61,15 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit { #[cfg(feature = "rkyv-serialize-no-std")] mod rkyv_impl { use super::Unit; - use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize}; + use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; impl Archive for Unit { type Archived = Unit; type Resolver = T::Resolver; - fn resolve( - &self, - pos: usize, - resolver: Self::Resolver, - out: &mut ::core::mem::MaybeUninit, - ) { - self.value.resolve( - pos + offset_of!(Self::Archived, value), - resolver, - project_struct!(out: Self::Archived => value), - ); + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + let (fp, fo) = out_field!(out.value); + self.value.resolve(pos + fp, resolver, fo); } } diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 0179f1ff..1b4eb26f 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -77,7 +77,7 @@ pub struct Isometry { mod rkyv_impl { use super::Isometry; use crate::{base::Scalar, geometry::Translation}; - use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize}; + use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; impl Archive for Isometry where @@ -86,22 +86,11 @@ mod rkyv_impl { type Archived = Isometry; type Resolver = (R::Resolver, as Archive>::Resolver); - fn resolve( - &self, - pos: usize, - resolver: Self::Resolver, - out: &mut core::mem::MaybeUninit, - ) { - self.rotation.resolve( - pos + offset_of!(Self::Archived, rotation), - resolver.0, - project_struct!(out: Self::Archived => rotation), - ); - self.translation.resolve( - pos + offset_of!(Self::Archived, translation), - resolver.1, - project_struct!(out: Self::Archived => translation), - ); + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + let (fp, fo) = out_field!(out.rotation); + self.rotation.resolve(pos + fp, resolver.0, fo); + let (fp, fo) = out_field!(out.translation); + self.translation.resolve(pos + fp, resolver.1, fo); } } diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 987c9757..43f31e2e 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -101,23 +101,15 @@ where mod rkyv_impl { use super::Quaternion; use crate::base::Vector4; - use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize}; + use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; impl Archive for Quaternion { type Archived = Quaternion; type Resolver = as Archive>::Resolver; - fn resolve( - &self, - pos: usize, - resolver: Self::Resolver, - out: &mut core::mem::MaybeUninit, - ) { - self.coords.resolve( - pos + offset_of!(Self::Archived, coords), - resolver, - project_struct!(out: Self::Archived => coords), - ); + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + let (fp, fo) = out_field!(out.coords); + self.coords.resolve(pos + fp, resolver, fo); } } diff --git a/src/geometry/scale.rs b/src/geometry/scale.rs index abaeeccc..23265bba 100755 --- a/src/geometry/scale.rs +++ b/src/geometry/scale.rs @@ -88,23 +88,15 @@ where mod rkyv_impl { use super::Scale; use crate::base::SVector; - use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize}; + use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; impl Archive for Scale { type Archived = Scale; type Resolver = as Archive>::Resolver; - fn resolve( - &self, - pos: usize, - resolver: Self::Resolver, - out: &mut core::mem::MaybeUninit, - ) { - self.vector.resolve( - pos + offset_of!(Self::Archived, vector), - resolver, - project_struct!(out: Self::Archived => vector), - ); + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + let (fp, fo) = out_field!(out.vector); + self.vector.resolve(pos + fp, resolver, fo); } } diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index e1921d0a..e7dc5ee8 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -88,23 +88,15 @@ where mod rkyv_impl { use super::Translation; use crate::base::SVector; - use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize}; + use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; impl Archive for Translation { type Archived = Translation; type Resolver = as Archive>::Resolver; - fn resolve( - &self, - pos: usize, - resolver: Self::Resolver, - out: &mut core::mem::MaybeUninit, - ) { - self.vector.resolve( - pos + offset_of!(Self::Archived, vector), - resolver, - project_struct!(out: Self::Archived => vector), - ); + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + let (fp, fo) = out_field!(out.vector); + self.vector.resolve(pos + fp, resolver, fo); } } From 1b6f2b83f7734708dd18dbf651084f632951329b Mon Sep 17 00:00:00 2001 From: zyansheep Date: Mon, 21 Mar 2022 12:47:03 -0400 Subject: [PATCH 2/5] add bytecheck for matrix --- Cargo.toml | 3 ++- src/base/matrix.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 { From 24b97932e14a9d1728ca146009bf0a8f5d82da02 Mon Sep 17 00:00:00 2001 From: zyansheep Date: Mon, 21 Mar 2022 21:03:17 -0400 Subject: [PATCH 3/5] add bytecheck impls --- src/base/array_storage.rs | 22 +++++++++++++++++++ src/base/dimension.rs | 15 +++++++++++++ src/base/matrix.rs | 14 ++++++++----- src/base/unit.rs | 21 +++++++++++++++++++ src/geometry/isometry.rs | 42 +++++++++++++++++++++++++++++++++++++ src/geometry/quaternion.rs | 22 +++++++++++++++++++ src/geometry/scale.rs | 21 +++++++++++++++++++ src/geometry/translation.rs | 21 +++++++++++++++++++ 8 files changed, 173 insertions(+), 5 deletions(-) diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index d6dab40a..78cb6dcd 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -307,3 +307,25 @@ mod rkyv_impl { } } } +#[cfg(feature = "rkyv-serialize")] +mod bytecheck_impl { + use std::ptr::addr_of; + + use bytecheck::{ArrayCheckError, CheckBytes}; + + use super::ArrayStorage; + + impl<__C: ?Sized, T, const R: usize, const C: usize> CheckBytes<__C> for ArrayStorage + where + T: CheckBytes<__C>, + { + type Error = ArrayCheckError>::Error>>; + unsafe fn check_bytes<'a>( + value: *const ArrayStorage, + context: &mut __C, + ) -> Result<&'a Self, Self::Error> { + let _ = <[[T; R]; C] as CheckBytes<__C>>::check_bytes(addr_of!((*value).0), context)?; + Ok(&*value) + } + } +} diff --git a/src/base/dimension.rs b/src/base/dimension.rs index 39e0459d..18c12803 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -257,6 +257,21 @@ mod rkyv_impl { } } } +#[cfg(feature = "rkyv-serialize")] +mod bytecheck_impl { + use bytecheck::CheckBytes; + + use super::Const; + impl<__C: ?Sized, const R: usize> CheckBytes<__C> for Const { + type Error = core::convert::Infallible; + unsafe fn check_bytes<'a>( + value: *const Const, + _context: &mut __C, + ) -> Result<&'a Self, Self::Error> { + Ok(&*value) + } + } +} pub trait ToConst { type Const: DimName; diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 63fbd0ce..2c481d37 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -293,7 +293,6 @@ 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; @@ -326,10 +325,15 @@ mod rkyv_impl { }) } } +} +#[cfg(feature = "rkyv-serialize")] +mod bytecheck_impl { + use bytecheck::CheckBytes; + use std::ptr::addr_of; - impl<__C: ?Sized, T, R, C, S: CheckBytes<__C>> - CheckBytes<__C> - for Matrix + use super::Matrix; + + impl<__C: ?Sized, T, R, C, S: CheckBytes<__C>> CheckBytes<__C> for Matrix where S: CheckBytes<__C>, { @@ -338,7 +342,7 @@ mod rkyv_impl { value: *const Matrix, context: &mut __C, ) -> Result<&'a Self, Self::Error> { - let _ = S::check_bytes(::core::ptr::addr_of!((*value).data), context)?; + let _ = S::check_bytes(addr_of!((*value).data), context)?; Ok(&*value) } } diff --git a/src/base/unit.rs b/src/base/unit.rs index d82c67ec..6828aa02 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -90,6 +90,27 @@ mod rkyv_impl { } } } +#[cfg(feature = "rkyv-serialize")] +mod bytecheck_impl { + use std::ptr::addr_of; + + use bytecheck::CheckBytes; + + use super::Unit; + impl<__C: ?Sized, T: CheckBytes<__C>> CheckBytes<__C> for Unit + where + T: CheckBytes<__C>, + { + type Error = >::Error; + unsafe fn check_bytes<'a>( + value: *const Unit, + context: &mut __C, + ) -> Result<&'a Self, Self::Error> { + let _ = T::check_bytes(addr_of!((*value).value), context)?; + Ok(&*value) + } + } +} #[cfg(feature = "cuda")] unsafe impl cust_core::DeviceCopy for Unit> diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 1b4eb26f..7f7175dd 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -121,6 +121,48 @@ mod rkyv_impl { } } } +#[cfg(feature = "rkyv-serialize")] +mod bytecheck_impl { + use crate::{Isometry, Scalar, Translation}; + use bytecheck::CheckBytes; + use std::{error::Error, fmt, ptr::addr_of}; + + #[derive(Debug)] + pub enum IsometryCheckBytesError { + Rotation(R), + Translation(T), + } + impl fmt::Display for IsometryCheckBytesError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Rotation(_) => write!(f, "failed to check bytes of isometry rotation"), + Self::Translation(_) => write!(f, "failed to check bytes of isometry translation"), + } + } + } + impl Error for IsometryCheckBytesError {} + + impl<__C: ?Sized, T: Scalar + CheckBytes<__C>, R: CheckBytes<__C>, const D: usize> + CheckBytes<__C> for Isometry + where + T: CheckBytes<__C>, + { + type Error = IsometryCheckBytesError< + as CheckBytes<__C>>::Error, + >::Error, + >; + unsafe fn check_bytes<'a>( + value: *const Isometry, + context: &mut __C, + ) -> Result<&'a Self, Self::Error> { + let _ = R::check_bytes(addr_of!((*value).rotation), context) + .map_err(|e| IsometryCheckBytesError::Rotation(e))?; + let _ = Translation::::check_bytes(addr_of!((*value).translation), context) + .map_err(|e| IsometryCheckBytesError::Translation(e))?; + Ok(&*value) + } + } +} impl hash::Hash for Isometry where diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 43f31e2e..71e38c4c 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -130,6 +130,28 @@ mod rkyv_impl { } } } +#[cfg(feature = "rkyv-serialize")] +mod bytecheck_impl { + use std::ptr::addr_of; + + use bytecheck::CheckBytes; + + use super::Quaternion; + use crate::Vector4; + impl<__C: ?Sized, T: CheckBytes<__C>> CheckBytes<__C> for Quaternion + where + T: CheckBytes<__C>, + { + type Error = as CheckBytes<__C>>::Error; + unsafe fn check_bytes<'a>( + value: *const Quaternion, + context: &mut __C, + ) -> Result<&'a Self, Self::Error> { + let _ = Vector4::check_bytes(addr_of!((*value).coords), context)?; + Ok(&*value) + } + } +} impl Quaternion where diff --git a/src/geometry/scale.rs b/src/geometry/scale.rs index 23265bba..333b63cb 100755 --- a/src/geometry/scale.rs +++ b/src/geometry/scale.rs @@ -118,6 +118,27 @@ mod rkyv_impl { } } } +#[cfg(feature = "rkyv-serialize")] +mod bytecheck_impl { + use std::ptr::addr_of; + + use bytecheck::CheckBytes; + + use crate::{SVector, Scale}; + impl<__C: ?Sized, T: CheckBytes<__C>, const D: usize> CheckBytes<__C> for Scale + where + T: CheckBytes<__C>, + { + type Error = as CheckBytes<__C>>::Error; + unsafe fn check_bytes<'a>( + value: *const Scale, + context: &mut __C, + ) -> Result<&'a Self, Self::Error> { + let _ = SVector::::check_bytes(addr_of!((*value).vector), context)?; + Ok(&*value) + } + } +} impl Scale { /// Inverts `self`. diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index e7dc5ee8..7af263bf 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -118,6 +118,27 @@ mod rkyv_impl { } } } +#[cfg(feature = "rkyv-serialize")] +mod bytecheck_impl { + use std::ptr::addr_of; + + use bytecheck::CheckBytes; + + use crate::{SVector, Translation}; + impl<__C: ?Sized, T: CheckBytes<__C>, const D: usize> CheckBytes<__C> for Translation + where + T: CheckBytes<__C>, + { + type Error = as CheckBytes<__C>>::Error; + unsafe fn check_bytes<'a>( + value: *const Translation, + context: &mut __C, + ) -> Result<&'a Self, Self::Error> { + let _ = SVector::::check_bytes(addr_of!((*value).vector), context)?; + Ok(&*value) + } + } +} impl Translation { /// Creates a new translation from the given vector. From ed41097d0c1dba439b1df9235e9de478845663c6 Mon Sep 17 00:00:00 2001 From: zyansheep Date: Tue, 22 Mar 2022 09:49:32 -0400 Subject: [PATCH 4/5] fix bytecheck feature in cargo.toml --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 90869f44..ffd37598 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,8 +52,8 @@ 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", "bytecheck" ] -rkyv-serialize = [ "rkyv-serialize-no-std", "rkyv/std" ] +rkyv-serialize-no-std = [ "rkyv" ] +rkyv-serialize = [ "rkyv-serialize-no-std", "rkyv/std", "bytecheck" ] # Randomness ## To use rand in a #[no-std] environment, enable the From e913beca889dc278d1c0d6cadd2008d3f9bcc0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 30 Apr 2022 10:32:10 +0200 Subject: [PATCH 5/5] Switch to derive macros for rkyv and bytecheck --- src/base/array_storage.rs | 61 ++------------------- src/base/dimension.rs | 50 ++++------------- src/base/matrix.rs | 65 ++-------------------- src/base/unit.rs | 59 ++------------------ src/geometry/dual_quaternion.rs | 5 ++ src/geometry/isometry.rs | 96 ++------------------------------- src/geometry/orthographic.rs | 5 ++ src/geometry/perspective.rs | 5 ++ src/geometry/point.rs | 5 ++ src/geometry/quaternion.rs | 61 ++------------------- src/geometry/rotation.rs | 5 ++ src/geometry/scale.rs | 61 ++------------------- src/geometry/similarity.rs | 5 ++ src/geometry/translation.rs | 61 ++------------------- src/lib.rs | 3 +- 15 files changed, 77 insertions(+), 470 deletions(-) diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index 78cb6dcd..3bc71e1a 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -27,6 +27,11 @@ use std::mem; /// A array-based statically sized matrix data storage. #[repr(transparent)] #[derive(Copy, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct ArrayStorage(pub [[T; R]; C]); @@ -273,59 +278,3 @@ unsafe impl by for ArrayStorage { } - -#[cfg(feature = "rkyv-serialize-no-std")] -mod rkyv_impl { - use super::ArrayStorage; - use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; - - impl Archive for ArrayStorage { - type Archived = ArrayStorage; - type Resolver = <[[T; R]; C] as Archive>::Resolver; - - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - let (fp, fo) = out_field!(out.0); - self.0.resolve(pos + fp, resolver, fo); - } - } - - impl, S: Fallible + ?Sized, const R: usize, const C: usize> Serialize - for ArrayStorage - { - fn serialize(&self, serializer: &mut S) -> Result { - self.0.serialize(serializer) - } - } - - impl - Deserialize, D> for ArrayStorage - where - T::Archived: Deserialize, - { - fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { - Ok(ArrayStorage(self.0.deserialize(deserializer)?)) - } - } -} -#[cfg(feature = "rkyv-serialize")] -mod bytecheck_impl { - use std::ptr::addr_of; - - use bytecheck::{ArrayCheckError, CheckBytes}; - - use super::ArrayStorage; - - impl<__C: ?Sized, T, const R: usize, const C: usize> CheckBytes<__C> for ArrayStorage - where - T: CheckBytes<__C>, - { - type Error = ArrayCheckError>::Error>>; - unsafe fn check_bytes<'a>( - value: *const ArrayStorage, - context: &mut __C, - ) -> Result<&'a Self, Self::Error> { - let _ = <[[T; R]; C] as CheckBytes<__C>>::check_bytes(addr_of!((*value).0), context)?; - Ok(&*value) - } - } -} diff --git a/src/base/dimension.rs b/src/base/dimension.rs index 18c12803..4be97586 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -13,6 +13,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// Dim of dynamically-sized algebraic entities. #[derive(Clone, Copy, Eq, PartialEq, Debug)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct Dynamic { value: usize, @@ -198,6 +203,11 @@ dim_ops!( ); #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct Const; @@ -233,46 +243,6 @@ impl<'de, const D: usize> Deserialize<'de> for Const { } } -#[cfg(feature = "rkyv-serialize-no-std")] -mod rkyv_impl { - use super::Const; - use rkyv::{Archive, Deserialize, Fallible, Serialize}; - - impl Archive for Const { - type Archived = Self; - type Resolver = (); - - unsafe fn resolve(&self, _: usize, _: Self::Resolver, _: *mut Self::Archived) {} - } - - impl Serialize for Const { - fn serialize(&self, _: &mut S) -> Result { - Ok(()) - } - } - - impl Deserialize for Const { - fn deserialize(&self, _: &mut D) -> Result { - Ok(Const) - } - } -} -#[cfg(feature = "rkyv-serialize")] -mod bytecheck_impl { - use bytecheck::CheckBytes; - - use super::Const; - impl<__C: ?Sized, const R: usize> CheckBytes<__C> for Const { - type Error = core::convert::Infallible; - unsafe fn check_bytes<'a>( - value: *const Const, - _context: &mut __C, - ) -> Result<&'a Self, Self::Error> { - Ok(&*value) - } - } -} - pub trait ToConst { type Const: DimName; } diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 2c481d37..8f8786c1 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -150,6 +150,11 @@ pub type MatrixCross = /// some concrete types for `T` and a compatible data storage type `S`). #[repr(C)] #[derive(Clone, Copy)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct Matrix { /// The data storage that contains all the matrix components. Disappointed? @@ -288,66 +293,6 @@ where { } -#[cfg(feature = "rkyv-serialize-no-std")] -mod rkyv_impl { - use super::Matrix; - use core::marker::PhantomData; - use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; - - impl Archive for Matrix { - type Archived = Matrix; - type Resolver = S::Resolver; - - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - let (fp, fo) = out_field!(out.data); - self.data.resolve(pos + fp, resolver, fo); - } - } - - impl, _S: Fallible + ?Sized> Serialize<_S> - for Matrix - { - fn serialize(&self, serializer: &mut _S) -> Result { - self.data.serialize(serializer) - } - } - - impl - Deserialize, D> - for Matrix - where - S::Archived: Deserialize, - { - fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { - Ok(Matrix { - data: self.data.deserialize(deserializer)?, - _phantoms: PhantomData, - }) - } - } -} -#[cfg(feature = "rkyv-serialize")] -mod bytecheck_impl { - use bytecheck::CheckBytes; - use std::ptr::addr_of; - - use super::Matrix; - - 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(addr_of!((*value).data), context)?; - Ok(&*value) - } - } -} - 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 6828aa02..6fc00092 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -21,6 +21,11 @@ use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealF /// in their documentation, read their dedicated pages directly. #[repr(transparent)] #[derive(Clone, Hash, Copy)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] // #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct Unit { pub(crate) value: T, @@ -58,60 +63,6 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit { } } -#[cfg(feature = "rkyv-serialize-no-std")] -mod rkyv_impl { - use super::Unit; - use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; - - impl Archive for Unit { - type Archived = Unit; - type Resolver = T::Resolver; - - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - let (fp, fo) = out_field!(out.value); - self.value.resolve(pos + fp, resolver, fo); - } - } - - impl, S: Fallible + ?Sized> Serialize for Unit { - fn serialize(&self, serializer: &mut S) -> Result { - self.value.serialize(serializer) - } - } - - impl Deserialize, D> for Unit - where - T::Archived: Deserialize, - { - fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { - Ok(Unit { - value: self.value.deserialize(deserializer)?, - }) - } - } -} -#[cfg(feature = "rkyv-serialize")] -mod bytecheck_impl { - use std::ptr::addr_of; - - use bytecheck::CheckBytes; - - use super::Unit; - impl<__C: ?Sized, T: CheckBytes<__C>> CheckBytes<__C> for Unit - where - T: CheckBytes<__C>, - { - type Error = >::Error; - unsafe fn check_bytes<'a>( - value: *const Unit, - context: &mut __C, - ) -> Result<&'a Self, Self::Error> { - let _ = T::check_bytes(addr_of!((*value).value), context)?; - Ok(&*value) - } - } -} - #[cfg(feature = "cuda")] unsafe impl cust_core::DeviceCopy for Unit> where diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 719ae13d..6f1b7053 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -40,6 +40,11 @@ use simba::scalar::{ClosedNeg, RealField}; /// See #[repr(C)] #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct DualQuaternion { /// The real component of the quaternion diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 7f7175dd..92169742 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -66,6 +66,11 @@ use crate::geometry::{AbstractRotation, Point, Translation}; Owned>: Deserialize<'de>, T: Scalar")) )] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] pub struct Isometry { /// The pure rotational part of this isometry. pub rotation: R, @@ -73,97 +78,6 @@ pub struct Isometry { pub translation: Translation, } -#[cfg(feature = "rkyv-serialize-no-std")] -mod rkyv_impl { - use super::Isometry; - use crate::{base::Scalar, geometry::Translation}; - use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; - - impl Archive for Isometry - where - T::Archived: Scalar, - { - type Archived = Isometry; - type Resolver = (R::Resolver, as Archive>::Resolver); - - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - let (fp, fo) = out_field!(out.rotation); - self.rotation.resolve(pos + fp, resolver.0, fo); - let (fp, fo) = out_field!(out.translation); - self.translation.resolve(pos + fp, resolver.1, fo); - } - } - - impl, R: Serialize, S: Fallible + ?Sized, const D: usize> - Serialize for Isometry - where - T::Archived: Scalar, - { - fn serialize(&self, serializer: &mut S) -> Result { - Ok(( - self.rotation.serialize(serializer)?, - self.translation.serialize(serializer)?, - )) - } - } - - impl - Deserialize, _D> for Isometry - where - T::Archived: Scalar + Deserialize, - R::Archived: Scalar + Deserialize, - { - fn deserialize(&self, deserializer: &mut _D) -> Result, _D::Error> { - Ok(Isometry { - rotation: self.rotation.deserialize(deserializer)?, - translation: self.translation.deserialize(deserializer)?, - }) - } - } -} -#[cfg(feature = "rkyv-serialize")] -mod bytecheck_impl { - use crate::{Isometry, Scalar, Translation}; - use bytecheck::CheckBytes; - use std::{error::Error, fmt, ptr::addr_of}; - - #[derive(Debug)] - pub enum IsometryCheckBytesError { - Rotation(R), - Translation(T), - } - impl fmt::Display for IsometryCheckBytesError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Rotation(_) => write!(f, "failed to check bytes of isometry rotation"), - Self::Translation(_) => write!(f, "failed to check bytes of isometry translation"), - } - } - } - impl Error for IsometryCheckBytesError {} - - impl<__C: ?Sized, T: Scalar + CheckBytes<__C>, R: CheckBytes<__C>, const D: usize> - CheckBytes<__C> for Isometry - where - T: CheckBytes<__C>, - { - type Error = IsometryCheckBytesError< - as CheckBytes<__C>>::Error, - >::Error, - >; - unsafe fn check_bytes<'a>( - value: *const Isometry, - context: &mut __C, - ) -> Result<&'a Self, Self::Error> { - let _ = R::check_bytes(addr_of!((*value).rotation), context) - .map_err(|e| IsometryCheckBytesError::Rotation(e))?; - let _ = Translation::::check_bytes(addr_of!((*value).translation), context) - .map_err(|e| IsometryCheckBytesError::Translation(e))?; - Ok(&*value) - } - } -} - impl hash::Hash for Isometry where Owned>: hash::Hash, diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 1119d4e3..7348f676 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -19,6 +19,11 @@ use crate::geometry::{Point3, Projective3}; /// A 3D orthographic projection stored as a homogeneous 4x4 matrix. #[repr(C)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] pub struct Orthographic3 { diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 8ebab3e4..351960bb 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -20,6 +20,11 @@ use crate::geometry::{Point3, Projective3}; /// A 3D perspective projection stored as a homogeneous 4x4 matrix. #[repr(C)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] pub struct Perspective3 { diff --git a/src/geometry/point.rs b/src/geometry/point.rs index cdc590fa..306c18e5 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -36,6 +36,11 @@ use std::mem::MaybeUninit; /// of said transformations for details. #[repr(C)] #[derive(Clone)] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] pub struct OPoint where DefaultAllocator: Allocator, diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 71e38c4c..f38dca6f 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -23,6 +23,11 @@ use crate::geometry::{Point3, Rotation}; /// that may be used as a rotation. #[repr(C)] #[derive(Copy, Clone)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct Quaternion { /// This quaternion as a 4D vector of coordinates in the `[ x, y, z, w ]` storage order. @@ -97,62 +102,6 @@ where } } -#[cfg(feature = "rkyv-serialize-no-std")] -mod rkyv_impl { - use super::Quaternion; - use crate::base::Vector4; - use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; - - impl Archive for Quaternion { - type Archived = Quaternion; - type Resolver = as Archive>::Resolver; - - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - let (fp, fo) = out_field!(out.coords); - self.coords.resolve(pos + fp, resolver, fo); - } - } - - impl, S: Fallible + ?Sized> Serialize for Quaternion { - fn serialize(&self, serializer: &mut S) -> Result { - self.coords.serialize(serializer) - } - } - - impl Deserialize, D> for Quaternion - where - T::Archived: Deserialize, - { - fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { - Ok(Quaternion { - coords: self.coords.deserialize(deserializer)?, - }) - } - } -} -#[cfg(feature = "rkyv-serialize")] -mod bytecheck_impl { - use std::ptr::addr_of; - - use bytecheck::CheckBytes; - - use super::Quaternion; - use crate::Vector4; - impl<__C: ?Sized, T: CheckBytes<__C>> CheckBytes<__C> for Quaternion - where - T: CheckBytes<__C>, - { - type Error = as CheckBytes<__C>>::Error; - unsafe fn check_bytes<'a>( - value: *const Quaternion, - context: &mut __C, - ) -> Result<&'a Self, Self::Error> { - let _ = Vector4::check_bytes(addr_of!((*value).coords), context)?; - Ok(&*value) - } - } -} - impl Quaternion where T::Element: SimdRealField, diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 4dbcfb43..2a8bf427 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -49,6 +49,11 @@ use crate::geometry::Point; /// * [Conversion to a matrix `matrix`, `to_homogeneous`…](#conversion-to-a-matrix) /// #[repr(C)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] pub struct Rotation { diff --git a/src/geometry/scale.rs b/src/geometry/scale.rs index 333b63cb..37da1ef0 100755 --- a/src/geometry/scale.rs +++ b/src/geometry/scale.rs @@ -17,6 +17,11 @@ use crate::geometry::Point; /// A scale which supports non-uniform scaling. #[repr(C)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] pub struct Scale { @@ -84,62 +89,6 @@ where } } -#[cfg(feature = "rkyv-serialize-no-std")] -mod rkyv_impl { - use super::Scale; - use crate::base::SVector; - use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; - - impl Archive for Scale { - type Archived = Scale; - type Resolver = as Archive>::Resolver; - - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - let (fp, fo) = out_field!(out.vector); - self.vector.resolve(pos + fp, resolver, fo); - } - } - - impl, S: Fallible + ?Sized, const D: usize> Serialize for Scale { - fn serialize(&self, serializer: &mut S) -> Result { - self.vector.serialize(serializer) - } - } - - impl Deserialize, _D> - for Scale - where - T::Archived: Deserialize, - { - fn deserialize(&self, deserializer: &mut _D) -> Result, _D::Error> { - Ok(Scale { - vector: self.vector.deserialize(deserializer)?, - }) - } - } -} -#[cfg(feature = "rkyv-serialize")] -mod bytecheck_impl { - use std::ptr::addr_of; - - use bytecheck::CheckBytes; - - use crate::{SVector, Scale}; - impl<__C: ?Sized, T: CheckBytes<__C>, const D: usize> CheckBytes<__C> for Scale - where - T: CheckBytes<__C>, - { - type Error = as CheckBytes<__C>>::Error; - unsafe fn check_bytes<'a>( - value: *const Scale, - context: &mut __C, - ) -> Result<&'a Self, Self::Error> { - let _ = SVector::::check_bytes(addr_of!((*value).vector), context)?; - Ok(&*value) - } - } -} - impl Scale { /// Inverts `self`. /// diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index 9658685e..8c38ff1e 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -34,6 +34,11 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; DefaultAllocator: Allocator>, Owned>: Deserialize<'de>")) )] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] pub struct Similarity { /// The part of this similarity that does not include the scaling factor. pub isometry: Isometry, diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 7af263bf..bef66f68 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -17,6 +17,11 @@ use crate::geometry::Point; /// A translation. #[repr(C)] +#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))] +#[cfg_attr( + feature = "rkyv-serialize-no-std", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Copy, Clone)] pub struct Translation { @@ -84,62 +89,6 @@ where } } -#[cfg(feature = "rkyv-serialize-no-std")] -mod rkyv_impl { - use super::Translation; - use crate::base::SVector; - use rkyv::{out_field, Archive, Deserialize, Fallible, Serialize}; - - impl Archive for Translation { - type Archived = Translation; - type Resolver = as Archive>::Resolver; - - unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - let (fp, fo) = out_field!(out.vector); - self.vector.resolve(pos + fp, resolver, fo); - } - } - - impl, S: Fallible + ?Sized, const D: usize> Serialize for Translation { - fn serialize(&self, serializer: &mut S) -> Result { - self.vector.serialize(serializer) - } - } - - impl Deserialize, _D> - for Translation - where - T::Archived: Deserialize, - { - fn deserialize(&self, deserializer: &mut _D) -> Result, _D::Error> { - Ok(Translation { - vector: self.vector.deserialize(deserializer)?, - }) - } - } -} -#[cfg(feature = "rkyv-serialize")] -mod bytecheck_impl { - use std::ptr::addr_of; - - use bytecheck::CheckBytes; - - use crate::{SVector, Translation}; - impl<__C: ?Sized, T: CheckBytes<__C>, const D: usize> CheckBytes<__C> for Translation - where - T: CheckBytes<__C>, - { - type Error = as CheckBytes<__C>>::Error; - unsafe fn check_bytes<'a>( - value: *const Translation, - context: &mut __C, - ) -> Result<&'a Self, Self::Error> { - let _ = SVector::::check_bytes(addr_of!((*value).vector), context)?; - Ok(&*value) - } - } -} - impl Translation { /// Creates a new translation from the given vector. #[inline] diff --git a/src/lib.rs b/src/lib.rs index 92b28dcb..1ee1a3ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,12 +78,13 @@ an optimized set of tools for computer graphics and physics. Those features incl unused_mut, unused_parens, unused_qualifications, - unused_results, rust_2018_idioms, rust_2018_compatibility, future_incompatible, missing_copy_implementations )] +#![cfg_attr(feature = "rkyv-serialize-no-std", warn(unused_results))] // TODO: deny this once bytecheck stops generating warnings. +#![cfg_attr(not(feature = "rkyv-serialize-no-std"), deny(unused_results))] #![doc( html_favicon_url = "https://nalgebra.org/img/favicon.ico", html_root_url = "https://docs.rs/nalgebra/0.25.0"