diff --git a/Cargo.toml b/Cargo.toml index 5ab9615..80b6dee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ rand = "0.8" log = "0.4" num = "0.4" glam = "0.18" +serde = { optional = true, version = "1", features = ["derive"] } [dev-dependencies] proptest = "1.0" @@ -28,6 +29,8 @@ criterion = "0.3" [features] bench = [] +# Unfortunately can't use "serde" as the feature name until https://github.com/rust-lang/cargo/issues/5565 lands +serde_impls = ["serde", "glam/serde"] [profile.release] lto = true diff --git a/src/aabb.rs b/src/aabb.rs index da63354..4a0302a 100644 --- a/src/aabb.rs +++ b/src/aabb.rs @@ -10,6 +10,7 @@ use crate::axis::Axis; /// AABB struct. #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))] #[allow(clippy::upper_case_acronyms)] pub struct AABB { /// Minimum coordinates diff --git a/src/bvh/bvh_impl.rs b/src/bvh/bvh_impl.rs index a1f8082..8a6dabb 100644 --- a/src/bvh/bvh_impl.rs +++ b/src/bvh/bvh_impl.rs @@ -23,6 +23,7 @@ use std::f32; /// [`BVH`]: struct.BVHNode.html /// #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))] #[allow(clippy::upper_case_acronyms)] pub enum BVHNode { /// Leaf node. @@ -402,6 +403,8 @@ impl BVHNode { /// [`BVH`]: struct.BVH.html /// #[allow(clippy::upper_case_acronyms)] +#[derive(Clone)] +#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))] pub struct BVH { /// The list of nodes of the [`BVH`]. /// diff --git a/src/lib.rs b/src/lib.rs index 55f6eca..f654507 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,6 +64,10 @@ //! let hit_sphere_aabbs = bvh.traverse(&ray, &spheres); //! ``` //! +//! ## Features +//! +//! - `serde_impls` (default **disabled**) - adds `Serialize` and `Deserialize` implementations for some types +//! #![deny(missing_docs)] #![cfg_attr(feature = "bench", feature(test))]