diff --git a/.travis.yml b/.travis.yml index 7539fd4..0d45982 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,6 @@ rust: - stable script: - - cargo build && cargo test + - cargo build && cargo test && cargo test --features "eders" - if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then cargo bench; fi - if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then cargo build --features "use_simd" && cargo test --features "use_simd" && cargo bench --features "use_simd"; fi diff --git a/Cargo.toml b/Cargo.toml index d329f09..f19a30b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,10 +37,10 @@ approx = "0.1" num-traits = "0.1" rand = "0.3" rustc-serialize = { version = "0.3", optional = true } -serde = { version = "0.8", optional = true } -serde_derive = { version = "0.8", optional = true } +serde = { version = "0.9", optional = true } +serde_derive = { version = "0.9", optional = true } simd = { version = "0.2", optional = true } [dev-dependencies] glium = "0.15" -serde_json = "0.8" +serde_json = "0.9" diff --git a/src/transform.rs b/src/transform.rs index 53bff7f..91bff72 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -64,11 +64,10 @@ pub struct Decomposed { pub disp: V, } -impl> Transform

for Decomposed where - // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092 -

::Scalar: BaseFloat, - // FIXME: Investigate why this is needed! -

::Diff: VectorSpace, +impl> Transform

for Decomposed + where

::Scalar: BaseFloat, + // FIXME: Investigate why this is needed! +

::Diff: VectorSpace { #[inline] fn one() -> Decomposed { @@ -116,10 +115,10 @@ impl> Transform

for Decomposed let r = self.rot.invert(); let d = r.rotate_vector(self.disp.clone()) * -s; Some(Decomposed { - scale: s, - rot: r, - disp: d, - }) + scale: s, + rot: r, + disp: d, + }) } } } @@ -150,7 +149,9 @@ impl> Transform2 for Decomposed, R> impl> Transform3 for Decomposed, R> {} impl ApproxEq for Decomposed - where S: ApproxEq, S::Scalar: ApproxEq, R: ApproxEq + where S: ApproxEq, + S::Scalar: ApproxEq, + R: ApproxEq { type Epsilon = E; @@ -190,18 +191,21 @@ mod eders_ser { use structure::VectorSpace; use super::Decomposed; use serde::{self, Serialize}; + use serde::ser::SerializeStruct; - impl Serialize for Decomposed - where V: Serialize, V::Scalar: Serialize, R: Serialize + impl Serialize for Decomposed + where V: Serialize + VectorSpace, + V::Scalar: Serialize, + R: Serialize { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> + fn serialize(&self, serializer: S) -> Result where S: serde::Serializer { - let mut state = try!(serializer.serialize_struct("Decomposed", 3)); - try!(serializer.serialize_struct_elt(&mut state, "scale", &self.scale)); - try!(serializer.serialize_struct_elt(&mut state, "rot", &self.rot)); - try!(serializer.serialize_struct_elt(&mut state, "disp", &self.disp)); - serializer.serialize_struct_end(state) + let mut struc = serializer.serialize_struct("Decomposed", 3)?; + struc.serialize_field("scale", &self.scale)?; + struc.serialize_field("rot", &self.rot)?; + struc.serialize_field("disp", &self.disp)?; + struc.end() } } } @@ -213,6 +217,7 @@ mod eders_de { use super::Decomposed; use serde::{self, Deserialize}; use std::marker::PhantomData; + use std::fmt; enum DecomposedField { Scale, @@ -221,7 +226,7 @@ mod eders_de { } impl Deserialize for DecomposedField { - fn deserialize(deserializer: &mut D) -> Result + fn deserialize(deserializer: D) -> Result where D: serde::Deserializer { struct DecomposedFieldVisitor; @@ -229,7 +234,11 @@ mod eders_de { impl serde::de::Visitor for DecomposedFieldVisitor { type Value = DecomposedField; - fn visit_str(&mut self, value: &str) -> Result + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("`scale`, `rot` or `disp`") + } + + fn visit_str(self, value: &str) -> Result where E: serde::de::Error { match value { @@ -246,9 +255,11 @@ mod eders_de { } impl Deserialize for Decomposed - where S: Deserialize, S::Scalar: Deserialize, R: Deserialize + where S: Deserialize, + S::Scalar: Deserialize, + R: Deserialize { - fn deserialize(deserializer: &mut D) -> Result, D::Error> + fn deserialize(deserializer: D) -> Result, D::Error> where D: serde::de::Deserializer { const FIELDS: &'static [&'static str] = &["scale", "rot", "disp"]; @@ -259,44 +270,57 @@ mod eders_de { struct DecomposedVisitor(PhantomData<(S, R)>); impl serde::de::Visitor for DecomposedVisitor - where S: Deserialize, S::Scalar: Deserialize, R: Deserialize + where S: Deserialize, + S::Scalar: Deserialize, + R: Deserialize { type Value = Decomposed; - fn visit_map(&mut self, mut visitor: V) -> Result, V::Error> + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("`scale`, `rot` and `disp` fields") + } + + fn visit_map(self, mut visitor: V) -> Result, V::Error> where V: serde::de::MapVisitor { let mut scale = None; let mut rot = None; let mut disp = None; - loop { - match try!(visitor.visit_key()) { - Some(DecomposedField::Scale) => { scale = Some(try!(visitor.visit_value())); }, - Some(DecomposedField::Rot) => { rot = Some(try!(visitor.visit_value())); }, - Some(DecomposedField::Disp) => { disp = Some(try!(visitor.visit_value())); }, - _ => { break; }, + while let Some(key) = visitor.visit_key()? { + match key { + DecomposedField::Scale => { + scale = Some(visitor.visit_value()?); + } + DecomposedField::Rot => { + rot = Some(visitor.visit_value()?); + } + DecomposedField::Disp => { + disp = Some(visitor.visit_value()?); + } } } let scale = match scale { Some(scale) => scale, - None => try!(visitor.missing_field("scale")), + None => return Err(serde::de::Error::missing_field("scale")), }; let rot = match rot { Some(rot) => rot, - None => try!(visitor.missing_field("rot")), + None => return Err(serde::de::Error::missing_field("rot")), }; let disp = match disp { Some(disp) => disp, - None => try!(visitor.missing_field("disp")), + None => return Err(serde::de::Error::missing_field("disp")), }; - try!(visitor.end()); - - Ok(Decomposed { scale: scale, rot: rot, disp: disp }) + Ok(Decomposed { + scale: scale, + rot: rot, + disp: disp, + }) } } }