Fix CheckBytes derives + drop Complex rkyv support for now
This commit is contained in:
parent
cce66c3abf
commit
e959f2eb9c
|
@ -54,8 +54,8 @@ convert-glam022 = [ "glam022" ]
|
|||
## `serde-serialize`.
|
||||
serde-serialize-no-std = [ "serde", "num-complex/serde" ]
|
||||
serde-serialize = [ "serde-serialize-no-std", "serde/std" ]
|
||||
rkyv-serialize-no-std = [ "rkyv", "rkyv_wrappers", "num-complex/rkyv" ]
|
||||
rkyv-serialize = [ "rkyv-serialize-no-std", "rkyv/std", "rkyv/validation", "bytecheck", "num-complex/bytecheck" ]
|
||||
rkyv-serialize-no-std = [ "rkyv/size_32" ]
|
||||
rkyv-serialize = [ "rkyv-serialize-no-std", "rkyv/std", "rkyv/validation", "bytecheck" ]
|
||||
|
||||
# Randomness
|
||||
## To use rand in a #[no-std] environment, enable the
|
||||
|
@ -83,7 +83,6 @@ 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", default-features = false, optional = true }
|
||||
rkyv_wrappers = { git = "https://github.com/rkyv/rkyv_contrib", optional = true }
|
||||
bytecheck = { version = "~0.6.1", optional = true }
|
||||
mint = { version = "0.5", optional = true }
|
||||
quickcheck = { version = "1", optional = true }
|
||||
|
@ -138,6 +137,3 @@ lto = true
|
|||
[package.metadata.docs.rs]
|
||||
# Enable all the features when building the docs on docs.rs
|
||||
all-features = true
|
||||
|
||||
[patch.crates-io]
|
||||
num-complex = { git = "https://github.com/zyansheep/num-complex" }
|
|
@ -38,10 +38,7 @@ use std::mem;
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
pub struct ArrayStorage<T, const R: usize, const C: usize>(pub [[T; R]; C]);
|
||||
|
||||
|
|
|
@ -208,12 +208,10 @@ 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",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
|
||||
archive(as = "Self")
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
pub struct Const<const R: usize>;
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ use std::mem;
|
|||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||
use rkyv::{with::With, Archive, Archived};
|
||||
use super::rkyv_wrappers::CustomPhantom;
|
||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||
use rkyv_wrappers::custom_phantom::CustomPhantom;
|
||||
use rkyv::{with::With, Archive, Archived};
|
||||
|
||||
use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub, Field, SupersetOf};
|
||||
use simba::simd::SimdPartialOrd;
|
||||
|
@ -167,10 +167,7 @@ pub type MatrixCross<T, R1, C1, R2, C2> =
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
pub struct Matrix<T, R, C, S> {
|
||||
/// The data storage that contains all the matrix components. Disappointed?
|
||||
|
|
|
@ -42,6 +42,9 @@ mod min_max;
|
|||
/// Mechanisms for working with values that may not be initialized.
|
||||
pub mod uninit;
|
||||
|
||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||
mod rkyv_wrappers;
|
||||
|
||||
pub use self::matrix::*;
|
||||
pub use self::norm::*;
|
||||
pub use self::scalar::*;
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
//! Wrapper that allows changing the generic type of a PhantomData<T>
|
||||
//!
|
||||
//! Copied from https://github.com/rkyv/rkyv_contrib (MIT-Apache2 licences) which isn’t published yet.
|
||||
|
||||
use rkyv::{
|
||||
with::{ArchiveWith, DeserializeWith, SerializeWith},
|
||||
Fallible,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// A wrapper that allows for changing the generic type of a PhantomData<T>.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::marker::PhantomData;
|
||||
/// use rkyv::{
|
||||
/// Archive, Serialize, Deserialize, Infallible, vec::ArchivedVec, Archived, with::With,
|
||||
/// };
|
||||
/// use rkyv_wrappers::custom_phantom::CustomPhantom;
|
||||
/// #[derive(Archive, Serialize, Deserialize, Debug, PartialEq, Eq, Default)]
|
||||
/// #[archive(as = "StructWithPhantom<T::Archived>", bound(archive = "
|
||||
/// T: Archive,
|
||||
/// With<PhantomData<T>, CustomPhantom<Archived<T>>>: Archive<Archived = PhantomData<Archived<T>>>
|
||||
/// "))]
|
||||
/// struct StructWithPhantom<T> {
|
||||
/// pub num: i32,
|
||||
/// #[with(CustomPhantom<T::Archived>)]
|
||||
/// pub phantom: PhantomData<T>,
|
||||
/// }
|
||||
/// let value = StructWithPhantom::<Vec<i32>>::default();
|
||||
/// let bytes = rkyv::to_bytes::<_, 1024>(&value).unwrap();
|
||||
/// let archived: &StructWithPhantom<ArchivedVec<i32>> = unsafe { rkyv::archived_root::<StructWithPhantom<Vec<i32>>>(&bytes) };
|
||||
///
|
||||
/// let deserialized: StructWithPhantom<Vec<i32>> = archived.deserialize(&mut Infallible).unwrap();
|
||||
/// assert_eq!(deserialized, value);
|
||||
/// ```
|
||||
pub struct CustomPhantom<NT: ?Sized> {
|
||||
_data: PhantomData<*const NT>,
|
||||
}
|
||||
|
||||
impl<OT: ?Sized, NT: ?Sized> ArchiveWith<PhantomData<OT>> for CustomPhantom<NT> {
|
||||
type Archived = PhantomData<NT>;
|
||||
type Resolver = ();
|
||||
|
||||
#[inline]
|
||||
unsafe fn resolve_with(
|
||||
_: &PhantomData<OT>,
|
||||
_: usize,
|
||||
_: Self::Resolver,
|
||||
_: *mut Self::Archived,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl<OT: ?Sized, NT: ?Sized, S: Fallible + ?Sized> SerializeWith<PhantomData<OT>, S>
|
||||
for CustomPhantom<NT>
|
||||
{
|
||||
#[inline]
|
||||
fn serialize_with(_: &PhantomData<OT>, _: &mut S) -> Result<Self::Resolver, S::Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<OT: ?Sized, NT: ?Sized, D: Fallible + ?Sized>
|
||||
DeserializeWith<PhantomData<NT>, PhantomData<OT>, D> for CustomPhantom<NT>
|
||||
{
|
||||
#[inline]
|
||||
fn deserialize_with(_: &PhantomData<NT>, _: &mut D) -> Result<PhantomData<OT>, D::Error> {
|
||||
Ok(PhantomData)
|
||||
}
|
||||
}
|
|
@ -31,10 +31,7 @@ use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealF
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
// #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
pub struct Unit<T> {
|
||||
pub(crate) value: T,
|
||||
|
|
|
@ -51,10 +51,7 @@ use simba::scalar::{ClosedNeg, RealField};
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
pub struct DualQuaternion<T> {
|
||||
/// The real component of the quaternion
|
||||
|
|
|
@ -30,10 +30,7 @@ use crate::geometry::{Point3, Projective3};
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Orthographic3<T> {
|
||||
|
|
|
@ -31,10 +31,7 @@ use crate::geometry::{Point3, Projective3};
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Perspective3<T> {
|
||||
|
|
|
@ -29,15 +29,12 @@ use crate::geometry::{Point3, Rotation};
|
|||
archive(
|
||||
as = "Quaternion<T::Archived>",
|
||||
bound(archive = "
|
||||
T: rkyv::Archive,
|
||||
Vector4<T>: rkyv::Archive<Archived = Vector4<T::Archived>>
|
||||
")
|
||||
T: rkyv::Archive,
|
||||
Vector4<T>: rkyv::Archive<Archived = Vector4<T::Archived>>
|
||||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
pub struct Quaternion<T> {
|
||||
/// This quaternion as a 4D vector of coordinates in the `[ x, y, z, w ]` storage order.
|
||||
|
|
|
@ -60,10 +60,7 @@ use crate::geometry::Point;
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Rotation<T, const D: usize> {
|
||||
|
|
|
@ -28,10 +28,7 @@ use crate::geometry::Point;
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Scale<T, const D: usize> {
|
||||
|
|
|
@ -28,10 +28,7 @@ use crate::geometry::Point;
|
|||
")
|
||||
)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "rkyv-serialize",
|
||||
archive_attr(derive(bytecheck::CheckBytes))
|
||||
)]
|
||||
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
|
||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Translation<T, const D: usize> {
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#![cfg(feature = "rkyv-serialize")]
|
||||
|
||||
use na::{
|
||||
DMatrix, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, Matrix2x3, Matrix3x4, Point2,
|
||||
Point3, Quaternion, Rotation2, Rotation3, Similarity2, Similarity3, SimilarityMatrix2,
|
||||
SimilarityMatrix3, Translation2, Translation3, Unit, Vector2,
|
||||
Isometry3, IsometryMatrix2, IsometryMatrix3, Matrix3x4, Point2, Point3, Quaternion, Rotation2,
|
||||
Rotation3, Similarity3, SimilarityMatrix2, SimilarityMatrix3, Translation2, Translation3,
|
||||
};
|
||||
use rand;
|
||||
use rkyv::{Archive, Deserialize, Infallible, Serialize};
|
||||
use rkyv::{Deserialize, Infallible};
|
||||
|
||||
macro_rules! test_rkyv_same_type(
|
||||
($($test: ident, $ty: ident);* $(;)*) => {$(
|
||||
|
@ -52,9 +51,9 @@ test_rkyv_same_type!(
|
|||
rkyv_same_type_point2, Point2;
|
||||
rkyv_same_type_translation2, Translation2;
|
||||
rkyv_same_type_rotation2, Rotation2;
|
||||
rkyv_same_type_isometry2, Isometry2;
|
||||
// rkyv_same_type_isometry2, Isometry2;
|
||||
rkyv_same_type_isometry_matrix2, IsometryMatrix2;
|
||||
rkyv_same_type_similarity2, Similarity2;
|
||||
// rkyv_same_type_similarity2, Similarity2;
|
||||
rkyv_same_type_similarity_matrix2, SimilarityMatrix2;
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue