Move rkyv impls into separate modules
This commit is contained in:
parent
38dd3345e0
commit
9fff10b1f0
|
@ -18,9 +18,6 @@ use std::mem;
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
|
||||||
use rkyv::{Archive, Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::base::allocator::Allocator;
|
use crate::base::allocator::Allocator;
|
||||||
use crate::base::default_allocator::DefaultAllocator;
|
use crate::base::default_allocator::DefaultAllocator;
|
||||||
use crate::base::dimension::{Const, ToTypenum};
|
use crate::base::dimension::{Const, ToTypenum};
|
||||||
|
@ -304,32 +301,43 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
impl<T: Archive, const R: usize, const C: usize> Archive for ArrayStorage<T, R, C> {
|
mod rkyv_impl {
|
||||||
|
use super::ArrayStorage;
|
||||||
|
use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize};
|
||||||
|
|
||||||
|
impl<T: Archive, const R: usize, const C: usize> Archive for ArrayStorage<T, R, C> {
|
||||||
type Archived = ArrayStorage<T::Archived, R, C>;
|
type Archived = ArrayStorage<T::Archived, R, C>;
|
||||||
type Resolver = <[[T; R]; C] as Archive>::Resolver;
|
type Resolver = <[[T; R]; C] as Archive>::Resolver;
|
||||||
|
|
||||||
fn resolve(&self, pos: usize, resolver: Self::Resolver, out: &mut core::mem::MaybeUninit<Self::Archived>) {
|
fn resolve(
|
||||||
|
&self,
|
||||||
|
pos: usize,
|
||||||
|
resolver: Self::Resolver,
|
||||||
|
out: &mut core::mem::MaybeUninit<Self::Archived>,
|
||||||
|
) {
|
||||||
self.0.resolve(
|
self.0.resolve(
|
||||||
pos + rkyv::offset_of!(Self::Archived, 0),
|
pos + offset_of!(Self::Archived, 0),
|
||||||
resolver,
|
resolver,
|
||||||
rkyv::project_struct!(out: Self::Archived => 0)
|
project_struct!(out: Self::Archived => 0),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Serialize<S>, S: Fallible + ?Sized, const R: usize, const C: usize> Serialize<S>
|
||||||
impl<T: Serialize<S>, S: rkyv::Fallible + ?Sized, const R: usize, const C: usize> Serialize<S> for ArrayStorage<T, R, C> {
|
for ArrayStorage<T, R, C>
|
||||||
|
{
|
||||||
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
||||||
Ok(self.0.serialize(serializer)?)
|
Ok(self.0.serialize(serializer)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Archive, D: Fallible + ?Sized, const R: usize, const C: usize>
|
||||||
impl<T: Archive, D: rkyv::Fallible + ?Sized, const R: usize, const C: usize> Deserialize<ArrayStorage<T, R, C>, D> for ArrayStorage<T::Archived, R, C>
|
Deserialize<ArrayStorage<T, R, C>, D> for ArrayStorage<T::Archived, R, C>
|
||||||
where
|
where
|
||||||
T::Archived: Deserialize<T, D>,
|
T::Archived: Deserialize<T, D>,
|
||||||
{
|
{
|
||||||
fn deserialize(&self, deserializer: &mut D) -> Result<ArrayStorage<T, R, C>, D::Error> {
|
fn deserialize(&self, deserializer: &mut D) -> Result<ArrayStorage<T, R, C>, D::Error> {
|
||||||
Ok(ArrayStorage(self.0.deserialize(deserializer)?))
|
Ok(ArrayStorage(self.0.deserialize(deserializer)?))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,6 @@ use typenum::{self, Diff, Max, Maximum, Min, Minimum, Prod, Quot, Sum, Unsigned}
|
||||||
#[cfg(feature = "serde-serialize-no-std")]
|
#[cfg(feature = "serde-serialize-no-std")]
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
|
||||||
use rkyv::{Archive, Deserialize, Serialize};
|
|
||||||
|
|
||||||
/// Dim of dynamically-sized algebraic entities.
|
/// Dim of dynamically-sized algebraic entities.
|
||||||
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
||||||
pub struct Dynamic {
|
pub struct Dynamic {
|
||||||
|
@ -235,26 +232,34 @@ impl<'de, const D: usize> Deserialize<'de> for Const<D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
impl<const R: usize> Archive for Const<R> {
|
mod rkyv_impl {
|
||||||
|
use super::Const;
|
||||||
|
use rkyv::{Archive, Deserialize, Fallible, Serialize};
|
||||||
|
|
||||||
|
impl<const R: usize> Archive for Const<R> {
|
||||||
type Archived = Self;
|
type Archived = Self;
|
||||||
type Resolver = ();
|
type Resolver = ();
|
||||||
|
|
||||||
fn resolve(&self, _: usize, _: Self::Resolver, _: &mut core::mem::MaybeUninit<Self::Archived>) {
|
fn resolve(
|
||||||
|
&self,
|
||||||
|
_: usize,
|
||||||
|
_: Self::Resolver,
|
||||||
|
_: &mut core::mem::MaybeUninit<Self::Archived>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<S: Fallible + ?Sized, const R: usize> Serialize<S> for Const<R> {
|
||||||
impl<S: rkyv::Fallible + ?Sized, const R: usize> Serialize<S> for Const<R> {
|
|
||||||
fn serialize(&self, _: &mut S) -> Result<Self::Resolver, S::Error> {
|
fn serialize(&self, _: &mut S) -> Result<Self::Resolver, S::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<D: Fallible + ?Sized, const R: usize> Deserialize<Self, D> for Const<R> {
|
||||||
impl<D: rkyv::Fallible + ?Sized, const R: usize> Deserialize<Self, D> for Const<R> {
|
|
||||||
fn deserialize(&self, _: &mut D) -> Result<Self, D::Error> {
|
fn deserialize(&self, _: &mut D) -> Result<Self, D::Error> {
|
||||||
Ok(Const)
|
Ok(Const)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToConst {
|
pub trait ToConst {
|
||||||
|
|
|
@ -16,9 +16,6 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
|
||||||
use rkyv::{Archive, Deserialize, Serialize};
|
|
||||||
|
|
||||||
use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub, Field, SupersetOf};
|
use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub, Field, SupersetOf};
|
||||||
use simba::simd::SimdPartialOrd;
|
use simba::simd::SimdPartialOrd;
|
||||||
|
|
||||||
|
@ -312,37 +309,50 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
impl<T: Archive, R: Archive, C: Archive, S: Archive> Archive for Matrix<T, R, C, S> {
|
mod rkyv_impl {
|
||||||
|
use super::Matrix;
|
||||||
|
use core::marker::PhantomData;
|
||||||
|
use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize};
|
||||||
|
|
||||||
|
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>;
|
type Archived = Matrix<T::Archived, R::Archived, C::Archived, S::Archived>;
|
||||||
type Resolver = S::Resolver;
|
type Resolver = S::Resolver;
|
||||||
|
|
||||||
fn resolve(&self, pos: usize, resolver: Self::Resolver, out: &mut core::mem::MaybeUninit<Self::Archived>) {
|
fn resolve(
|
||||||
|
&self,
|
||||||
|
pos: usize,
|
||||||
|
resolver: Self::Resolver,
|
||||||
|
out: &mut core::mem::MaybeUninit<Self::Archived>,
|
||||||
|
) {
|
||||||
self.data.resolve(
|
self.data.resolve(
|
||||||
pos + rkyv::offset_of!(Self::Archived, data),
|
pos + offset_of!(Self::Archived, data),
|
||||||
resolver,
|
resolver,
|
||||||
rkyv::project_struct!(out: Self::Archived => data)
|
project_struct!(out: Self::Archived => data),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Archive, R: Archive, C: Archive, S: Serialize<_S>, _S: Fallible + ?Sized> Serialize<_S>
|
||||||
impl<T: Archive, R: Archive, C: Archive, S: Serialize<_S>, _S: rkyv::Fallible + ?Sized> Serialize<_S> for Matrix<T, R, C, S> {
|
for Matrix<T, R, C, S>
|
||||||
|
{
|
||||||
fn serialize(&self, serializer: &mut _S) -> Result<Self::Resolver, _S::Error> {
|
fn serialize(&self, serializer: &mut _S) -> Result<Self::Resolver, _S::Error> {
|
||||||
Ok(self.data.serialize(serializer)?)
|
Ok(self.data.serialize(serializer)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Archive, R: Archive, C: Archive, S: Archive, D: Fallible + ?Sized>
|
||||||
impl<T: Archive, R: Archive, C: Archive, S: Archive, D: rkyv::Fallible + ?Sized> Deserialize<Matrix<T, R, C, S>, D> for Matrix<T::Archived, R::Archived, C::Archived, S::Archived>
|
Deserialize<Matrix<T, R, C, S>, D>
|
||||||
where
|
for Matrix<T::Archived, R::Archived, C::Archived, S::Archived>
|
||||||
|
where
|
||||||
S::Archived: Deserialize<S, D>,
|
S::Archived: Deserialize<S, D>,
|
||||||
{
|
{
|
||||||
fn deserialize(&self, deserializer: &mut D) -> Result<Matrix<T, R, C, S>, D::Error> {
|
fn deserialize(&self, deserializer: &mut D) -> Result<Matrix<T, R, C, S>, D::Error> {
|
||||||
Ok(Matrix {
|
Ok(Matrix {
|
||||||
data: self.data.deserialize(deserializer)?,
|
data: self.data.deserialize(deserializer)?,
|
||||||
_phantoms: PhantomData,
|
_phantoms: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, R, C, S> Matrix<T, R, C, S> {
|
impl<T, R, C, S> Matrix<T, R, C, S> {
|
||||||
|
|
|
@ -6,9 +6,6 @@ use std::ops::Deref;
|
||||||
#[cfg(feature = "serde-serialize-no-std")]
|
#[cfg(feature = "serde-serialize-no-std")]
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
|
||||||
use rkyv::{Archive, Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
|
@ -75,36 +72,44 @@ impl<T: Abomonation> Abomonation for Unit<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
impl<T: Archive> Archive for Unit<T> {
|
mod rkyv_impl {
|
||||||
|
use super::Unit;
|
||||||
|
use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize};
|
||||||
|
|
||||||
|
impl<T: Archive> Archive for Unit<T> {
|
||||||
type Archived = Unit<T::Archived>;
|
type Archived = Unit<T::Archived>;
|
||||||
type Resolver = T::Resolver;
|
type Resolver = T::Resolver;
|
||||||
|
|
||||||
fn resolve(&self, pos: usize, resolver: Self::Resolver, out: &mut ::core::mem::MaybeUninit<Self::Archived>) {
|
fn resolve(
|
||||||
|
&self,
|
||||||
|
pos: usize,
|
||||||
|
resolver: Self::Resolver,
|
||||||
|
out: &mut ::core::mem::MaybeUninit<Self::Archived>,
|
||||||
|
) {
|
||||||
self.value.resolve(
|
self.value.resolve(
|
||||||
pos + rkyv::offset_of!(Self::Archived, value),
|
pos + offset_of!(Self::Archived, value),
|
||||||
resolver,
|
resolver,
|
||||||
rkyv::project_struct!(out: Self::Archived => value),
|
project_struct!(out: Self::Archived => value),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Serialize<S>, S: Fallible + ?Sized> Serialize<S> for Unit<T> {
|
||||||
impl<T: Serialize<S>, S: rkyv::Fallible + ?Sized> Serialize<S> for Unit<T> {
|
|
||||||
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
||||||
Ok(self.value.serialize(serializer)?)
|
Ok(self.value.serialize(serializer)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Archive, D: Fallible + ?Sized> Deserialize<Unit<T>, D> for Unit<T::Archived>
|
||||||
impl<T: Archive, D: rkyv::Fallible + ?Sized> Deserialize<Unit<T>, D> for Unit<T::Archived>
|
where
|
||||||
where
|
|
||||||
T::Archived: Deserialize<T, D>,
|
T::Archived: Deserialize<T, D>,
|
||||||
{
|
{
|
||||||
fn deserialize(&self, deserializer: &mut D) -> Result<Unit<T>, D::Error> {
|
fn deserialize(&self, deserializer: &mut D) -> Result<Unit<T>, D::Error> {
|
||||||
Ok(Unit {
|
Ok(Unit {
|
||||||
value: self.value.deserialize(deserializer)?,
|
value: self.value.deserialize(deserializer)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, R, C, S> PartialEq for Unit<Matrix<T, R, C, S>>
|
impl<T, R, C, S> PartialEq for Unit<Matrix<T, R, C, S>>
|
||||||
|
|
|
@ -7,9 +7,6 @@ use std::io::{Result as IOResult, Write};
|
||||||
#[cfg(feature = "serde-serialize-no-std")]
|
#[cfg(feature = "serde-serialize-no-std")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
|
||||||
use rkyv::{Archive, Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
|
@ -102,52 +99,63 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
impl<T: Scalar + Archive, R: Archive, const D: usize> Archive for Isometry<T, R, D>
|
mod rkyv_impl {
|
||||||
where
|
use super::Isometry;
|
||||||
|
use crate::{base::Scalar, geometry::Translation};
|
||||||
|
use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize};
|
||||||
|
|
||||||
|
impl<T: Scalar + Archive, R: Archive, const D: usize> Archive for Isometry<T, R, D>
|
||||||
|
where
|
||||||
T::Archived: Scalar,
|
T::Archived: Scalar,
|
||||||
{
|
{
|
||||||
type Archived = Isometry<T::Archived, R::Archived, D>;
|
type Archived = Isometry<T::Archived, R::Archived, D>;
|
||||||
type Resolver = (R::Resolver, <Translation<T, D> as Archive>::Resolver);
|
type Resolver = (R::Resolver, <Translation<T, D> as Archive>::Resolver);
|
||||||
|
|
||||||
fn resolve(&self, pos: usize, resolver: Self::Resolver, out: &mut core::mem::MaybeUninit<Self::Archived>) {
|
fn resolve(
|
||||||
|
&self,
|
||||||
|
pos: usize,
|
||||||
|
resolver: Self::Resolver,
|
||||||
|
out: &mut core::mem::MaybeUninit<Self::Archived>,
|
||||||
|
) {
|
||||||
self.rotation.resolve(
|
self.rotation.resolve(
|
||||||
pos + rkyv::offset_of!(Self::Archived, rotation),
|
pos + offset_of!(Self::Archived, rotation),
|
||||||
resolver.0,
|
resolver.0,
|
||||||
rkyv::project_struct!(out: Self::Archived => rotation)
|
project_struct!(out: Self::Archived => rotation),
|
||||||
);
|
);
|
||||||
self.translation.resolve(
|
self.translation.resolve(
|
||||||
pos + rkyv::offset_of!(Self::Archived, translation),
|
pos + offset_of!(Self::Archived, translation),
|
||||||
resolver.1,
|
resolver.1,
|
||||||
rkyv::project_struct!(out: Self::Archived => translation)
|
project_struct!(out: Self::Archived => translation),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Scalar + Serialize<S>, R: Serialize<S>, S: Fallible + ?Sized, const D: usize>
|
||||||
impl<T: Scalar + Serialize<S>, R: Serialize<S>, S: rkyv::Fallible + ?Sized, const D: usize> Serialize<S> for Isometry<T, R, D>
|
Serialize<S> for Isometry<T, R, D>
|
||||||
where
|
where
|
||||||
T::Archived: Scalar,
|
T::Archived: Scalar,
|
||||||
{
|
{
|
||||||
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
||||||
Ok((
|
Ok((
|
||||||
self.rotation.serialize(serializer)?,
|
self.rotation.serialize(serializer)?,
|
||||||
self.translation.serialize(serializer)?,
|
self.translation.serialize(serializer)?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Scalar + Archive, R: Archive, _D: Fallible + ?Sized, const D: usize>
|
||||||
impl<T: Scalar + Archive, R: Archive, _D: rkyv::Fallible + ?Sized, const D: usize> Deserialize<Isometry<T, R, D>, _D> for Isometry<T::Archived, R::Archived, D>
|
Deserialize<Isometry<T, R, D>, _D> for Isometry<T::Archived, R::Archived, D>
|
||||||
where
|
where
|
||||||
T::Archived: Scalar + Deserialize<T, _D>,
|
T::Archived: Scalar + Deserialize<T, _D>,
|
||||||
R::Archived: Scalar + Deserialize<R, _D>,
|
R::Archived: Scalar + Deserialize<R, _D>,
|
||||||
{
|
{
|
||||||
fn deserialize(&self, deserializer: &mut _D) -> Result<Isometry<T, R, D>, _D::Error> {
|
fn deserialize(&self, deserializer: &mut _D) -> Result<Isometry<T, R, D>, _D::Error> {
|
||||||
Ok(Isometry {
|
Ok(Isometry {
|
||||||
rotation: self.rotation.deserialize(deserializer)?,
|
rotation: self.rotation.deserialize(deserializer)?,
|
||||||
translation: self.translation.deserialize(deserializer)?,
|
translation: self.translation.deserialize(deserializer)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Scalar + hash::Hash, R: hash::Hash, const D: usize> hash::Hash for Isometry<T, R, D>
|
impl<T: Scalar + hash::Hash, R: hash::Hash, const D: usize> hash::Hash for Isometry<T, R, D>
|
||||||
|
|
|
@ -10,9 +10,6 @@ use crate::base::storage::Owned;
|
||||||
#[cfg(feature = "serde-serialize-no-std")]
|
#[cfg(feature = "serde-serialize-no-std")]
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
|
||||||
use rkyv::{Archive, Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
|
@ -117,36 +114,45 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
impl<T: Archive> Archive for Quaternion<T> {
|
mod rkyv_impl {
|
||||||
|
use super::Quaternion;
|
||||||
|
use crate::base::Vector4;
|
||||||
|
use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize};
|
||||||
|
|
||||||
|
impl<T: Archive> Archive for Quaternion<T> {
|
||||||
type Archived = Quaternion<T::Archived>;
|
type Archived = Quaternion<T::Archived>;
|
||||||
type Resolver = <Vector4<T> as Archive>::Resolver;
|
type Resolver = <Vector4<T> as Archive>::Resolver;
|
||||||
|
|
||||||
fn resolve(&self, pos: usize, resolver: Self::Resolver, out: &mut core::mem::MaybeUninit<Self::Archived>) {
|
fn resolve(
|
||||||
|
&self,
|
||||||
|
pos: usize,
|
||||||
|
resolver: Self::Resolver,
|
||||||
|
out: &mut core::mem::MaybeUninit<Self::Archived>,
|
||||||
|
) {
|
||||||
self.coords.resolve(
|
self.coords.resolve(
|
||||||
pos + rkyv::offset_of!(Self::Archived, coords),
|
pos + offset_of!(Self::Archived, coords),
|
||||||
resolver,
|
resolver,
|
||||||
rkyv::project_struct!(out: Self::Archived => coords)
|
project_struct!(out: Self::Archived => coords),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Serialize<S>, S: Fallible + ?Sized> Serialize<S> for Quaternion<T> {
|
||||||
impl<T: Serialize<S>, S: rkyv::Fallible + ?Sized> Serialize<S> for Quaternion<T> {
|
|
||||||
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
||||||
Ok(self.coords.serialize(serializer)?)
|
Ok(self.coords.serialize(serializer)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Archive, D: Fallible + ?Sized> Deserialize<Quaternion<T>, D> for Quaternion<T::Archived>
|
||||||
impl<T: Archive, D: rkyv::Fallible + ?Sized> Deserialize<Quaternion<T>, D> for Quaternion<T::Archived>
|
where
|
||||||
where
|
|
||||||
T::Archived: Deserialize<T, D>,
|
T::Archived: Deserialize<T, D>,
|
||||||
{
|
{
|
||||||
fn deserialize(&self, deserializer: &mut D) -> Result<Quaternion<T>, D::Error> {
|
fn deserialize(&self, deserializer: &mut D) -> Result<Quaternion<T>, D::Error> {
|
||||||
Ok(Quaternion {
|
Ok(Quaternion {
|
||||||
coords: self.coords.deserialize(deserializer)?,
|
coords: self.coords.deserialize(deserializer)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: SimdRealField> Quaternion<T>
|
impl<T: SimdRealField> Quaternion<T>
|
||||||
|
|
|
@ -8,9 +8,6 @@ use std::io::{Result as IOResult, Write};
|
||||||
#[cfg(feature = "serde-serialize-no-std")]
|
#[cfg(feature = "serde-serialize-no-std")]
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
|
||||||
use rkyv::{Archive, Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
|
|
||||||
|
@ -101,36 +98,46 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
impl<T: Archive, const D: usize> Archive for Translation<T, D> {
|
mod rkyv_impl {
|
||||||
|
use super::Translation;
|
||||||
|
use crate::base::SVector;
|
||||||
|
use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize};
|
||||||
|
|
||||||
|
impl<T: Archive, const D: usize> Archive for Translation<T, D> {
|
||||||
type Archived = Translation<T::Archived, D>;
|
type Archived = Translation<T::Archived, D>;
|
||||||
type Resolver = <SVector<T, D> as Archive>::Resolver;
|
type Resolver = <SVector<T, D> as Archive>::Resolver;
|
||||||
|
|
||||||
fn resolve(&self, pos: usize, resolver: Self::Resolver, out: &mut core::mem::MaybeUninit<Self::Archived>) {
|
fn resolve(
|
||||||
|
&self,
|
||||||
|
pos: usize,
|
||||||
|
resolver: Self::Resolver,
|
||||||
|
out: &mut core::mem::MaybeUninit<Self::Archived>,
|
||||||
|
) {
|
||||||
self.vector.resolve(
|
self.vector.resolve(
|
||||||
pos + rkyv::offset_of!(Self::Archived, vector),
|
pos + offset_of!(Self::Archived, vector),
|
||||||
resolver,
|
resolver,
|
||||||
rkyv::project_struct!(out: Self::Archived => vector)
|
project_struct!(out: Self::Archived => vector),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Serialize<S>, S: Fallible + ?Sized, const D: usize> Serialize<S> for Translation<T, D> {
|
||||||
impl<T: Serialize<S>, S: rkyv::Fallible + ?Sized, const D: usize> Serialize<S> for Translation<T, D> {
|
|
||||||
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
|
||||||
Ok(self.vector.serialize(serializer)?)
|
Ok(self.vector.serialize(serializer)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
impl<T: Archive, _D: Fallible + ?Sized, const D: usize> Deserialize<Translation<T, D>, _D>
|
||||||
impl<T: Archive, _D: rkyv::Fallible + ?Sized, const D: usize> Deserialize<Translation<T, D>, _D> for Translation<T::Archived, D>
|
for Translation<T::Archived, D>
|
||||||
where
|
where
|
||||||
T::Archived: Deserialize<T, _D>,
|
T::Archived: Deserialize<T, _D>,
|
||||||
{
|
{
|
||||||
fn deserialize(&self, deserializer: &mut _D) -> Result<Translation<T, D>, _D::Error> {
|
fn deserialize(&self, deserializer: &mut _D) -> Result<Translation<T, D>, _D::Error> {
|
||||||
Ok(Translation {
|
Ok(Translation {
|
||||||
vector: self.vector.deserialize(deserializer)?,
|
vector: self.vector.deserialize(deserializer)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Scalar, const D: usize> Translation<T, D> {
|
impl<T: Scalar, const D: usize> Translation<T, D> {
|
||||||
|
|
Loading…
Reference in New Issue