Skip to content

Commit

Permalink
Merge pull request #119 from dimforge/rkyv-self-archives
Browse files Browse the repository at this point in the history
rkyv: let archived objects be Self when possible
  • Loading branch information
sebcrozet authored Jan 13, 2023
2 parents 192dfb5 + 3c1cfbd commit 9e7abd6
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ parry2d-f64 = { path = "crates/parry2d-f64" }
parry3d-f64 = { path = "crates/parry3d-f64" }

#simba = { path = "../simba" }
#simba = { git = "https://github.com/dimforge/simba", rev = "d928e4aedbf8ee03043abae38c8f846dba4801e5" }
# nalgebra = { git = "https://github.com/dimforge/nalgebra" }
simba = { git = "https://github.com/dimforge/simba", rev = "45a5266eb36ed9d25907e9bf9130cd4ac846a748" }
nalgebra = { git = "https://github.com/dimforge/nalgebra", rev = "0cf79aef0e6155befc3279a3145f1940822b8377" }
3 changes: 2 additions & 1 deletion src/bounding_volume/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use na::ComplexField; // for .abs()
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(Debug, PartialEq, Copy, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion src/bounding_volume/bounding_sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use num::Zero;
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[derive(Debug, PartialEq, Copy, Clone)]
#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ the rust programming language.
#![deny(non_camel_case_types)]
#![deny(unused_parens)]
#![deny(non_upper_case_globals)]
#![deny(unused_qualifications)]
#![deny(unused_results)]
#![warn(missing_docs)] // TODO: deny this
#![warn(unused_imports)]
#![allow(missing_copy_implementations)]
#![doc(html_root_url = "http://docs.rs/parry/0.1.1")]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "rkyv"), deny(unused_qualifications))] // TODO: deny that everytime

#[cfg(all(
feature = "simd-is-enabled",
Expand Down
3 changes: 2 additions & 1 deletion src/mass_properties/mass_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const EPSILON: Real = f32::EPSILON as Real;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
/// The local mass properties of a rigid-body.
pub struct MassProperties {
Expand Down
6 changes: 4 additions & 2 deletions src/partitioning/qbvh/qbvh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub type SimdNodeIndex = u32;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
/// The index of one specific node of a Qbvh.
Expand Down Expand Up @@ -91,7 +92,8 @@ bitflags! {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(Default)]
Expand Down
3 changes: 2 additions & 1 deletion src/query/contact/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::mem;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
pub struct Contact {
/// Position of the contact on the first object.
Expand Down
3 changes: 2 additions & 1 deletion src/query/point/point_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use na;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
pub struct PointProjection {
/// Whether or not the point to project was inside of the shape.
Expand Down
6 changes: 4 additions & 2 deletions src/query/ray/ray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::shape::FeatureId;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[repr(C)]
Expand Down Expand Up @@ -60,7 +61,8 @@ impl Ray {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
pub struct RayIntersection {
/// The time of impact of the ray with the object. The exact contact point can be computed
Expand Down
3 changes: 2 additions & 1 deletion src/shape/capsule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use either::Either;
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[repr(C)]
Expand Down
3 changes: 2 additions & 1 deletion src/shape/cone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use na::RealField; // for .copysign()
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(PartialEq, Debug, Copy, Clone)]
Expand Down
9 changes: 6 additions & 3 deletions src/shape/convex_polyhedron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use na::ComplexField; // for .abs()
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct Vertex {
Expand All @@ -23,7 +24,8 @@ pub struct Vertex {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct Edge {
Expand All @@ -46,7 +48,8 @@ impl Edge {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct Face {
Expand Down
3 changes: 2 additions & 1 deletion src/shape/cuboid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use na::RealField; // for .copysign()
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(PartialEq, Debug, Copy, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion src/shape/cylinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use na::RealField; // for .copysign()
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(PartialEq, Debug, Copy, Clone)]
Expand Down
6 changes: 4 additions & 2 deletions src/shape/feature_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub enum FeatureId {
Expand Down Expand Up @@ -58,7 +59,8 @@ impl FeatureId {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
/// A feature id where the feature type is packed into the same value as the feature index.
Expand Down
3 changes: 2 additions & 1 deletion src/shape/half_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use na::Unit;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[repr(C)]
Expand Down
3 changes: 2 additions & 1 deletion src/shape/heightfield3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ bitflags! {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(Default)]
Expand Down
3 changes: 2 additions & 1 deletion src/shape/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use std::mem;
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(PartialEq, Debug, Copy, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion src/shape/tetrahedron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use na::ComplexField; // for .abs()
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(Copy, Clone, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion src/shape/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::shape::PackedFeatureId;
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(PartialEq, Debug, Copy, Clone, Default)]
Expand Down
12 changes: 8 additions & 4 deletions src/shape/trimesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ impl TriMeshConnectedComponents<DefaultStorage> {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[repr(C)] // Needed for Cuda.
Expand All @@ -169,7 +170,8 @@ pub struct TopoVertex {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[repr(C)] // Needed for Cuda.
Expand All @@ -184,7 +186,8 @@ pub struct TopoFace {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[repr(C)] // Needed for Cuda.
Expand Down Expand Up @@ -259,7 +262,8 @@ bitflags::bitflags! {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[repr(C)] // Needed for Cuda.
Expand Down
6 changes: 4 additions & 2 deletions src/utils/sdp_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::ops::{Add, Mul};
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self", bound(archive = "N: rkyv::Archive<Archived = N>"))
)]
pub struct SdpMatrix2<N> {
/// The component at the first row and first column of this matrix.
Expand Down Expand Up @@ -112,7 +113,8 @@ impl Mul<Real> for SdpMatrix2<Real> {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self", bound(archive = "N: rkyv::Archive<Archived = N>"))
)]
pub struct SdpMatrix3<N> {
/// The component at the first row and first column of this matrix.
Expand Down

0 comments on commit 9e7abd6

Please sign in to comment.