Skip to content

Commit

Permalink
Add some optional serde implementations, as well as .clone on BVH
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanhs committed Sep 2, 2021
1 parent 4554a9a commit 1ed62c1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/aabb.rs
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/bvh/bvh_impl.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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`].
///
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Expand Up @@ -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))]
Expand Down

0 comments on commit 1ed62c1

Please sign in to comment.