diff --git a/Cargo.toml b/Cargo.toml index bfd3f166..1a356c3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,8 @@ convert-bytemuck = [ "bytemuck" ] serde-serialize-no-std = [ "serde", "num-complex/serde" ] serde-serialize = [ "serde-serialize-no-std", "serde/std" ] abomonation-serialize = [ "abomonation" ] +rkyv-serialize-no-std = [ "rkyv" ] +rkyv-serialize = [ "rkyv-serialize-no-std", "rkyv/std" ] # Randomness ## To use rand in a #[no-std] environment, enable the @@ -74,6 +76,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 } abomonation = { version = "0.7", optional = true } +rkyv = { version = "~0.6.3", default-features = false, features = ["const_generics"], optional = true } mint = { version = "0.5", optional = true } glam = { version = "0.13", optional = true } quickcheck = { version = "1", optional = true } @@ -81,7 +84,7 @@ pest = { version = "2", optional = true } pest_derive = { version = "2", optional = true } bytemuck = { version = "1.5", optional = true } matrixcompare-core = { version = "0.1", optional = true } -proptest = { version = "1", optional = true, default-features = false, features = ["std"] } +proptest = { version = "1", optional = true, default-features = false, features = ["std"] } [dev-dependencies] serde_json = "1.0" diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index 68da4c51..e575229c 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -18,6 +18,9 @@ use std::mem; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; +#[cfg(feature = "rkyv-serialize-no-std")] +use rkyv::{Archive, Deserialize, Serialize}; + use crate::base::allocator::Allocator; use crate::base::default_allocator::DefaultAllocator; use crate::base::dimension::{Const, ToTypenum}; @@ -34,6 +37,7 @@ use crate::base::Scalar; /// A array-based statically sized matrix data storage. #[repr(C)] #[derive(Copy, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "rkyv-serialize-no-std", derive(Archive, Deserialize, Serialize))] pub struct ArrayStorage(pub [[T; R]; C]); // TODO: remove this once the stdlib implements Default for arrays. diff --git a/src/base/dimension.rs b/src/base/dimension.rs index dd87647d..2c51b2f4 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -11,6 +11,9 @@ use typenum::{self, Diff, Max, Maximum, Min, Minimum, Prod, Quot, Sum, Unsigned} #[cfg(feature = "serde-serialize-no-std")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; +#[cfg(feature = "rkyv-serialize-no-std")] +use rkyv::{Archive, Deserialize, Serialize}; + /// Dim of dynamically-sized algebraic entities. #[derive(Clone, Copy, Eq, PartialEq, Debug)] pub struct Dynamic { @@ -197,6 +200,7 @@ dim_ops!( ); #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "rkyv-serialize-no-std", derive(Archive, Deserialize, Serialize))] pub struct Const; /// Trait implemented exclusively by type-level integers. diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 3cde8a4f..c7e02e22 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -16,6 +16,9 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; +#[cfg(feature = "rkyv-serialize-no-std")] +use rkyv::{Archive, Deserialize, Serialize}; + use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub, Field, SupersetOf}; use simba::simd::SimdPartialOrd; @@ -153,6 +156,7 @@ 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-no-std", derive(Archive, Deserialize, Serialize))] pub struct Matrix { /// The data storage that contains all the matrix components. Disappointed? /// diff --git a/src/base/unit.rs b/src/base/unit.rs index c2e60da3..4b1d1948 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -6,6 +6,9 @@ use std::ops::Deref; #[cfg(feature = "serde-serialize-no-std")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; +#[cfg(feature = "rkyv-serialize-no-std")] +use rkyv::{Archive, Deserialize, Serialize}; + #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -26,6 +29,7 @@ use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealF /// in their documentation, read their dedicated pages directly. #[repr(transparent)] #[derive(Clone, Hash, Debug, Copy)] +#[cfg_attr(feature = "rkyv-serialize-no-std", derive(Archive, Deserialize, Serialize))] pub struct Unit { pub(crate) value: T, } diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index c5fd844c..7c8686c0 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -7,6 +7,9 @@ use std::io::{Result as IOResult, Write}; #[cfg(feature = "serde-serialize-no-std")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "rkyv-serialize-no-std")] +use rkyv::{Archive, Deserialize, Serialize}; + #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -68,6 +71,7 @@ use crate::geometry::{AbstractRotation, Point, Translation}; DefaultAllocator: Allocator>, Owned>: Deserialize<'de>")) )] +#[cfg_attr(feature = "rkyv-serialize-no-std", derive(Archive, Serialize, Deserialize))] pub struct Isometry { /// The pure rotational part of this isometry. pub rotation: R, diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 365095b8..9a920a8a 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -10,6 +10,9 @@ use crate::base::storage::Owned; #[cfg(feature = "serde-serialize-no-std")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; +#[cfg(feature = "rkyv-serialize-no-std")] +use rkyv::{Archive, Deserialize, Serialize}; + #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -28,6 +31,7 @@ use crate::geometry::{Point3, Rotation}; /// that may be used as a rotation. #[repr(C)] #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "rkyv-serialize-no-std", derive(Archive, Deserialize, Serialize))] pub struct Quaternion { /// This quaternion as a 4D vector of coordinates in the `[ x, y, z, w ]` storage order. pub coords: Vector4, diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 1a8f4b04..92747dab 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -8,6 +8,9 @@ use std::io::{Result as IOResult, Write}; #[cfg(feature = "serde-serialize-no-std")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; +#[cfg(feature = "rkyv-serialize-no-std")] +use rkyv::{Archive, Deserialize, Serialize}; + #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -23,6 +26,7 @@ use crate::geometry::Point; /// A translation. #[repr(C)] #[derive(Debug)] +#[cfg_attr(feature = "rkyv-serialize-no-std", derive(Archive, Deserialize, Serialize))] pub struct Translation { /// The translation coordinates, i.e., how much is added to a point's coordinates when it is /// translated.