From e464ab58b5971453a593d5d6c0b7eec4843b2648 Mon Sep 17 00:00:00 2001 From: marek Date: Fri, 12 Feb 2021 01:10:01 +0100 Subject: [PATCH] rkyv Integration --- Cargo.toml | 1 + src/angle.rs | 2 ++ src/euler.rs | 1 + src/lib.rs | 4 ++++ src/matrix.rs | 3 +++ src/point.rs | 3 +++ src/projection.rs | 3 +++ src/quaternion.rs | 1 + src/rotation.rs | 2 ++ src/transform.rs | 1 + src/vector.rs | 4 ++++ 11 files changed, 25 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index a9e3d717..7c96cf5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ num-traits = "0.2" # small_rng used only for benchmarks rand = { version = "0.8", features = ["small_rng"], optional = true } serde = { version = "1.0", features = ["serde_derive"], optional = true } +rkyv = { version = "0.3.1", optional = true } # works only in rust toolchain up to 1.32, disabled indefinitely #simd = { version = "0.2", optional = true } diff --git a/src/angle.rs b/src/angle.rs index 9f084227..2ef232c4 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -38,6 +38,7 @@ use num::BaseFloat; #[repr(C)] #[derive(Copy, Clone, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Rad(pub S); /// An angle, in degrees. @@ -46,6 +47,7 @@ pub struct Rad(pub S); #[repr(C)] #[derive(Copy, Clone, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Deg(pub S); impl From> for Deg diff --git a/src/euler.rs b/src/euler.rs index 1e66bb20..85bcbb1b 100644 --- a/src/euler.rs +++ b/src/euler.rs @@ -81,6 +81,7 @@ use quaternion::Quaternion; #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Euler { /// The angle to apply around the _x_ axis. Also known at the _pitch_. pub x: A, diff --git a/src/lib.rs b/src/lib.rs index b9642cbb..34859da5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,6 +66,10 @@ extern crate rand; #[macro_use] extern crate serde; +#[cfg(feature = "rkyv")] +#[macro_use] +extern crate rkyv; + #[cfg(feature = "simd")] extern crate simd; diff --git a/src/matrix.rs b/src/matrix.rs index 7245c278..3ccaa1dc 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -45,6 +45,7 @@ use mint; #[repr(C)] #[derive(Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Matrix2 { /// The first column of the matrix. pub x: Vector2, @@ -58,6 +59,7 @@ pub struct Matrix2 { #[repr(C)] #[derive(Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Matrix3 { /// The first column of the matrix. pub x: Vector3, @@ -73,6 +75,7 @@ pub struct Matrix3 { #[repr(C)] #[derive(Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Matrix4 { /// The first column of the matrix. pub x: Vector4, diff --git a/src/point.rs b/src/point.rs index faf2a6db..2a393b5a 100644 --- a/src/point.rs +++ b/src/point.rs @@ -37,6 +37,7 @@ use mint; #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Point1 { pub x: S, } @@ -47,6 +48,7 @@ pub struct Point1 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Point2 { pub x: S, pub y: S, @@ -58,6 +60,7 @@ pub struct Point2 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Point3 { pub x: S, pub y: S, diff --git a/src/projection.rs b/src/projection.rs index 8ba3dc0a..bc8874a7 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -80,6 +80,7 @@ pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct PerspectiveFov { pub fovy: Rad, pub aspect: S, @@ -176,6 +177,7 @@ impl From> for Matrix4 { /// A perspective projection with arbitrary left/right/bottom/top distances #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Perspective { pub left: S, pub right: S, @@ -241,6 +243,7 @@ impl From> for Matrix4 { /// An orthographic projection with arbitrary left/right/bottom/top distances #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Ortho { pub left: S, pub right: S, diff --git a/src/quaternion.rs b/src/quaternion.rs index 06fb6376..570b887a 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -45,6 +45,7 @@ use mint; #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Quaternion { /// The vector part of the quaternion. pub v: Vector3, diff --git a/src/rotation.rs b/src/rotation.rs index 1e801b6f..88023831 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -164,6 +164,7 @@ pub trait Rotation3: /// ``` #[derive(PartialEq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Basis2 { mat: Matrix2, } @@ -310,6 +311,7 @@ impl fmt::Debug for Basis2 { /// been restricted to a subset of those implemented on `Matrix3`. #[derive(PartialEq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Basis3 { mat: Matrix3, } diff --git a/src/transform.rs b/src/transform.rs index 151bf3d7..3dcf3105 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -70,6 +70,7 @@ pub trait Transform: Sized + One { /// A generic transformation consisting of a rotation, /// displacement vector and scale amount. #[derive(Copy, Clone, Debug, PartialEq)] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Decomposed { pub scale: V::Scalar, pub rot: R, diff --git a/src/vector.rs b/src/vector.rs index adcc5816..0b37d9cb 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -39,6 +39,7 @@ use mint; #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Vector1 { /// The x component of the vector. pub x: S, @@ -50,6 +51,7 @@ pub struct Vector1 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Vector2 { /// The x component of the vector. pub x: S, @@ -63,6 +65,7 @@ pub struct Vector2 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Vector3 { /// The x component of the vector. pub x: S, @@ -78,6 +81,7 @@ pub struct Vector3 { #[repr(C)] #[derive(PartialEq, Eq, Copy, Clone, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "rkyv", derive(Archive, Unarchive))] pub struct Vector4 { /// The x component of the vector. pub x: S,