From 37e0b9af83e8dab79e6e50aff5e5162a29b2ce22 Mon Sep 17 00:00:00 2001 From: 66OJ66 <59021291+66OJ66@users.noreply.github.com> Date: Mon, 19 Jun 2023 20:29:48 +0000 Subject: [PATCH] Add serde behind a feature (#31) * Add serde * Revert bvh2d git url to original --------- Co-authored-by: 66OJ66 --- Cargo.toml | 2 ++ src/lib.rs | 4 ++++ src/primitives.rs | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 737c274..1bbd030 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ stats = [] verbose = [] async = [] no-default-baking = [] +serde = ["glam/serde", "bvh2d/serde", "dep:serde"] [dependencies] tracing = { version = "0.1", optional = true } @@ -24,6 +25,7 @@ hashbrown = { version = "0.13" } glam = { version = "0.23", features = ["approx"] } smallvec = { version = "1.9", features = ["union", "const_generics"] } bvh2d = { version = "0.3", git = "https://github.com/mockersf/bvh2d" } +serde = { version = "1.0.164", features = ["derive"], optional = true } [dev-dependencies] criterion = "0.4" diff --git a/src/lib.rs b/src/lib.rs index 6f00980..f95288c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,9 @@ use instance::{EdgeSide, InstanceStep}; #[cfg(feature = "tracing")] use tracing::instrument; +#[cfg(feature = "serde")] +use serde::{Serialize, Deserialize}; + #[cfg(feature = "async")] mod async_helpers; mod helpers; @@ -58,6 +61,7 @@ pub struct Path { /// A navigation mesh #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Mesh { /// List of `Vertex` in this mesh pub vertices: Vec, diff --git a/src/primitives.rs b/src/primitives.rs index 39d41a6..ff45a6f 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -6,8 +6,12 @@ use tracing::instrument; use glam::Vec2; +#[cfg(feature = "serde")] +use serde::{Serialize, Deserialize}; + /// A point that lies on an edge of a polygon in the navigation mesh. #[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Vertex { /// Coordinates of that point. pub coords: Vec2, @@ -31,6 +35,7 @@ impl Vertex { /// A polygon in the navigation mesh. #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Polygon { /// List of vertex making this polygon, in counter clockwise order. pub vertices: Vec,