diff --git a/Cargo.toml b/Cargo.toml index 1ba2949c..f968fd0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,8 @@ num-traits = "0.1" num-complex = "0.1" approx = "0.1" alga = "0.5" -serde = { version = "0.9", optional = true } -serde_derive = { version = "0.9", optional = true } +serde = { version = "1.0", optional = true } +serde_derive = { version = "1.0", optional = true } # clippy = "*" [dependencies.quickcheck] @@ -36,4 +36,4 @@ optional = true version = "0.3" [dev-dependencies] -serde_json = "0.9" +serde_json = "1.0" diff --git a/src/core/matrix_array.rs b/src/core/matrix_array.rs index ebc20e00..5acd67d3 100644 --- a/src/core/matrix_array.rs +++ b/src/core/matrix_array.rs @@ -7,7 +7,7 @@ use serde::{Serialize, Serializer, Deserialize, Deserializer}; #[cfg(feature = "serde-serialize")] use serde::ser::SerializeSeq; #[cfg(feature = "serde-serialize")] -use serde::de::{SeqVisitor, Visitor}; +use serde::de::{SeqAccess, Visitor, Error}; #[cfg(feature = "serde-serialize")] use std::mem; #[cfg(feature = "serde-serialize")] @@ -216,7 +216,7 @@ where N: Scalar + Serialize, fn serialize(&self, serializer: S) -> Result where S: Serializer { - let mut serializer = serializer.serialize_seq_fixed_size(R::dim() * C::dim())?; + let mut serializer = serializer.serialize_seq(Some(R::dim() * C::dim()))?; for e in self.iter() { serializer.serialize_element(e)?; @@ -228,8 +228,8 @@ where N: Scalar + Serialize, #[cfg(feature = "serde-serialize")] -impl Deserialize for MatrixArray -where N: Scalar + Deserialize, +impl<'a, N, R, C> Deserialize<'a> for MatrixArray +where N: Scalar + Deserialize<'a>, R: DimName, C: DimName, R::Value: Mul, @@ -237,10 +237,8 @@ where N: Scalar + Deserialize, fn deserialize(deserializer: D) -> Result - where D: Deserializer { - - let len = R::dim() * C::dim(); - deserializer.deserialize_seq_fixed_size(len, MatrixArrayVisitor::new()) + where D: Deserializer<'a> { + deserializer.deserialize_seq(MatrixArrayVisitor::new()) } } @@ -268,8 +266,8 @@ where N: Scalar, } #[cfg(feature = "serde-serialize")] -impl Visitor for MatrixArrayVisitor -where N: Scalar + Deserialize, +impl<'a, N, R, C> Visitor<'a> for MatrixArrayVisitor +where N: Scalar + Deserialize<'a>, R: DimName, C: DimName, R::Value: Mul, @@ -283,16 +281,21 @@ where N: Scalar + Deserialize, #[inline] fn visit_seq(self, mut visitor: V) -> Result, V::Error> - where V: SeqVisitor { + where V: SeqAccess<'a> { let mut out: Self::Value = unsafe { mem::uninitialized() }; let mut curr = 0; - while let Some(value) = try!(visitor.visit()) { + while let Some(value) = try!(visitor.next_element()) { out[curr] = value; curr += 1; } - Ok(out) + if curr == R::dim() * C::dim() { + Ok(out) + } + else { + Err(V::Error::invalid_length(curr, &self)) + } } }