From 9937c6029a1667ac71d84f5b723b0254bd892ae7 Mon Sep 17 00:00:00 2001 From: Jeff Olhoeft Date: Tue, 13 Nov 2018 19:20:45 -0800 Subject: [PATCH 1/2] Add optional serde support --- Cargo.toml | 16 +++++++++++++++- src/lib.rs | 7 +++++++ src/point.rs | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c36b303..b7681c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,20 @@ license = "MIT" [dependencies] rand = "0.3" -ordered-float = "0.5.0" log = "0.3" fnv = "1.0" +serde = { version = "1.0", optional = true } +serde_derive = { version = "1.0", optional = true } + +[target.'cfg(not(features="serde_derive"))'.dependencies.ordered-float] +version = "0.5.0" + +[target.'cfg(features="serde_derive")'.dependencies.ordered-float] +version = "0.5.0" +features = ["serde"] + +[dev-dependencies] +serde_test = "1.0" + +[features] +serde_support = ["serde", "serde_derive"] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 658cc99..29676ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,13 @@ extern crate rand; extern crate ordered_float; extern crate fnv; +#[cfg(feature = "serde_support")] +extern crate serde; + +#[cfg(feature = "serde_support")] +#[macro_use] +extern crate serde_derive; + mod geometry; mod point; mod dcel; diff --git a/src/point.rs b/src/point.rs index 78ba934..c16e266 100644 --- a/src/point.rs +++ b/src/point.rs @@ -6,6 +6,7 @@ use std::cmp::Ordering; /// A point in two dimensions #[derive(Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))] pub struct Point { /// x coordinate pub x: OrderedFloat, From 6093bcc84071c23577eff38a9cb29e1e23bbed8d Mon Sep 17 00:00:00 2001 From: Jeff Olhoeft Date: Thu, 29 Nov 2018 12:14:06 -0800 Subject: [PATCH 2/2] Crate updatse, remove unused random support --- Cargo.toml | 7 +++---- src/lib.rs | 1 - src/point.rs | 8 -------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b7681c3..b3684ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,17 +11,16 @@ readme = "Readme.md" license = "MIT" [dependencies] -rand = "0.3" -log = "0.3" +log = "0.4" fnv = "1.0" serde = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true } [target.'cfg(not(features="serde_derive"))'.dependencies.ordered-float] -version = "0.5.0" +version = "1.0" [target.'cfg(features="serde_derive")'.dependencies.ordered-float] -version = "0.5.0" +version = "1.0" features = ["serde"] [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 29676ac..560834a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ #[macro_use] extern crate log; -extern crate rand; extern crate ordered_float; extern crate fnv; diff --git a/src/point.rs b/src/point.rs index c16e266..ac59f90 100644 --- a/src/point.rs +++ b/src/point.rs @@ -1,4 +1,3 @@ -use rand::{Rand, Rng, random}; use std::ops::{Sub, Mul, Add}; use std::fmt; use ordered_float::OrderedFloat; @@ -37,13 +36,6 @@ impl fmt::Debug for Point { } } -#[allow(unused_variables)] -impl Rand for Point { - fn rand(rng: &mut R) -> Point { - Point::new(random::(), random::()) - } -} - impl Mul for Point { type Output = Point;