Update to serde 1.0.

This commit is contained in:
Sébastien Crozet 2017-04-24 20:05:45 +02:00 committed by Sébastien Crozet
parent cbbe1a2aee
commit 485abf1462
2 changed files with 19 additions and 16 deletions

View File

@ -27,8 +27,8 @@ num-traits = "0.1"
num-complex = "0.1" num-complex = "0.1"
approx = "0.1" approx = "0.1"
alga = "0.5" alga = "0.5"
serde = { version = "0.9", optional = true } serde = { version = "1.0", optional = true }
serde_derive = { version = "0.9", optional = true } serde_derive = { version = "1.0", optional = true }
# clippy = "*" # clippy = "*"
[dependencies.quickcheck] [dependencies.quickcheck]
@ -36,4 +36,4 @@ optional = true
version = "0.3" version = "0.3"
[dev-dependencies] [dev-dependencies]
serde_json = "0.9" serde_json = "1.0"

View File

@ -7,7 +7,7 @@ use serde::{Serialize, Serializer, Deserialize, Deserializer};
#[cfg(feature = "serde-serialize")] #[cfg(feature = "serde-serialize")]
use serde::ser::SerializeSeq; use serde::ser::SerializeSeq;
#[cfg(feature = "serde-serialize")] #[cfg(feature = "serde-serialize")]
use serde::de::{SeqVisitor, Visitor}; use serde::de::{SeqAccess, Visitor, Error};
#[cfg(feature = "serde-serialize")] #[cfg(feature = "serde-serialize")]
use std::mem; use std::mem;
#[cfg(feature = "serde-serialize")] #[cfg(feature = "serde-serialize")]
@ -216,7 +216,7 @@ where N: Scalar + Serialize,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer { 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() { for e in self.iter() {
serializer.serialize_element(e)?; serializer.serialize_element(e)?;
@ -228,8 +228,8 @@ where N: Scalar + Serialize,
#[cfg(feature = "serde-serialize")] #[cfg(feature = "serde-serialize")]
impl<N, R, C> Deserialize for MatrixArray<N, R, C> impl<'a, N, R, C> Deserialize<'a> for MatrixArray<N, R, C>
where N: Scalar + Deserialize, where N: Scalar + Deserialize<'a>,
R: DimName, R: DimName,
C: DimName, C: DimName,
R::Value: Mul<C::Value>, R::Value: Mul<C::Value>,
@ -237,10 +237,8 @@ where N: Scalar + Deserialize,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer { where D: Deserializer<'a> {
deserializer.deserialize_seq(MatrixArrayVisitor::new())
let len = R::dim() * C::dim();
deserializer.deserialize_seq_fixed_size(len, MatrixArrayVisitor::new())
} }
} }
@ -268,8 +266,8 @@ where N: Scalar,
} }
#[cfg(feature = "serde-serialize")] #[cfg(feature = "serde-serialize")]
impl<N, R, C> Visitor for MatrixArrayVisitor<N, R, C> impl<'a, N, R, C> Visitor<'a> for MatrixArrayVisitor<N, R, C>
where N: Scalar + Deserialize, where N: Scalar + Deserialize<'a>,
R: DimName, R: DimName,
C: DimName, C: DimName,
R::Value: Mul<C::Value>, R::Value: Mul<C::Value>,
@ -283,16 +281,21 @@ where N: Scalar + Deserialize,
#[inline] #[inline]
fn visit_seq<V>(self, mut visitor: V) -> Result<MatrixArray<N, R, C>, V::Error> fn visit_seq<V>(self, mut visitor: V) -> Result<MatrixArray<N, R, C>, V::Error>
where V: SeqVisitor { where V: SeqAccess<'a> {
let mut out: Self::Value = unsafe { mem::uninitialized() }; let mut out: Self::Value = unsafe { mem::uninitialized() };
let mut curr = 0; let mut curr = 0;
while let Some(value) = try!(visitor.visit()) { while let Some(value) = try!(visitor.next_element()) {
out[curr] = value; out[curr] = value;
curr += 1; curr += 1;
} }
Ok(out) if curr == R::dim() * C::dim() {
Ok(out)
}
else {
Err(V::Error::invalid_length(curr, &self))
}
} }
} }