diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/datetime.rs | 26 | ||||
-rw-r--r-- | src/de.rs | 136 | ||||
-rw-r--r-- | src/ser.rs | 51 | ||||
-rw-r--r-- | src/value.rs | 103 |
4 files changed, 151 insertions, 165 deletions
diff --git a/src/datetime.rs b/src/datetime.rs index b3c82d6..7917cad 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -315,13 +315,13 @@ impl ser::Serialize for Datetime { } } -impl de::Deserialize for Datetime { +impl<'de> de::Deserialize<'de> for Datetime { fn deserialize<D>(deserializer: D) -> Result<Datetime, D::Error> - where D: de::Deserializer + where D: de::Deserializer<'de> { struct DatetimeVisitor; - impl de::Visitor for DatetimeVisitor { + impl<'de> de::Visitor<'de> for DatetimeVisitor { type Value = Datetime; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { @@ -329,13 +329,13 @@ impl de::Deserialize for Datetime { } fn visit_map<V>(self, mut visitor: V) -> Result<Datetime, V::Error> - where V: de::MapVisitor + where V: de::MapAccess<'de> { - let value = visitor.visit_key::<DatetimeKey>()?; + let value = visitor.next_key::<DatetimeKey>()?; if value.is_none() { return Err(de::Error::custom("datetime key not found")) } - let v: DatetimeFromString = visitor.visit_value()?; + let v: DatetimeFromString = visitor.next_value()?; Ok(v.value) } @@ -350,13 +350,13 @@ impl de::Deserialize for Datetime { struct DatetimeKey; -impl de::Deserialize for DatetimeKey { +impl<'de> de::Deserialize<'de> for DatetimeKey { fn deserialize<D>(deserializer: D) -> Result<DatetimeKey, D::Error> - where D: de::Deserializer + where D: de::Deserializer<'de> { struct FieldVisitor; - impl de::Visitor for FieldVisitor { + impl<'de> de::Visitor<'de> for FieldVisitor { type Value = (); fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { @@ -374,7 +374,7 @@ impl de::Deserialize for DatetimeKey { } } - deserializer.deserialize_struct_field(FieldVisitor)?; + deserializer.deserialize_identifier(FieldVisitor)?; Ok(DatetimeKey) } } @@ -383,13 +383,13 @@ pub struct DatetimeFromString { pub value: Datetime, } -impl de::Deserialize for DatetimeFromString { +impl<'de> de::Deserialize<'de> for DatetimeFromString { fn deserialize<D>(deserializer: D) -> Result<DatetimeFromString, D::Error> - where D: de::Deserializer + where D: de::Deserializer<'de> { struct Visitor; - impl de::Visitor for Visitor { + impl<'de> de::Visitor<'de> for Visitor { type Value = DatetimeFromString; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { @@ -19,8 +19,8 @@ use datetime::{SERDE_STRUCT_FIELD_NAME, SERDE_STRUCT_NAME}; /// /// This function will attempt to interpret `bytes` as UTF-8 data and then /// deserialize `T` from the TOML document provided. -pub fn from_slice<T>(bytes: &[u8]) -> Result<T, Error> - where T: de::Deserialize, +pub fn from_slice<'de, T>(bytes: &'de [u8]) -> Result<T, Error> + where T: de::Deserialize<'de>, { match str::from_utf8(bytes) { Ok(s) => from_str(s), @@ -32,8 +32,8 @@ pub fn from_slice<T>(bytes: &[u8]) -> Result<T, Error> /// /// This function will attempt to interpret `s` as a TOML document and /// deserialize `T` from the document. -pub fn from_str<T>(s: &str) -> Result<T, Error> - where T: de::Deserialize, +pub fn from_str<'de, T>(s: &'de str) -> Result<T, Error> + where T: de::Deserialize<'de>, { let mut d = Deserializer::new(s); let ret = T::deserialize(&mut d)?; @@ -132,11 +132,11 @@ pub struct Deserializer<'a> { tokens: Tokenizer<'a>, } -impl<'a, 'b> de::Deserializer for &'b mut Deserializer<'a> { +impl<'de, 'b> de::Deserializer<'de> for &'b mut Deserializer<'de> { type Error = Error; - fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error> - where V: de::Visitor, + fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error> + where V: de::Visitor<'de>, { let mut tables = Vec::new(); let mut cur_table = Table { @@ -192,10 +192,10 @@ impl<'a, 'b> de::Deserializer for &'b mut Deserializer<'a> { }) } - forward_to_deserialize! { + forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq - seq_fixed_size bytes byte_buf map struct unit enum newtype_struct - struct_field ignored_any unit_struct tuple_struct tuple option + bytes byte_buf map struct unit enum newtype_struct + ignored_any unit_struct tuple_struct tuple option identifier } } @@ -207,23 +207,23 @@ struct Table<'a> { } #[doc(hidden)] -pub struct MapVisitor<'a: 'b, 'b> { - values: vec::IntoIter<(Cow<'a, str>, Value<'a>)>, - next_value: Option<(Cow<'a, str>, Value<'a>)>, +pub struct MapVisitor<'de: 'b, 'b> { + values: vec::IntoIter<(Cow<'de, str>, Value<'de>)>, + next_value: Option<(Cow<'de, str>, Value<'de>)>, depth: usize, cur: usize, cur_parent: usize, max: usize, - tables: &'b mut [Table<'a>], + tables: &'b mut [Table<'de>], array: bool, - de: &'b mut Deserializer<'a>, + de: &'b mut Deserializer<'de>, } -impl<'a, 'b> de::MapVisitor for MapVisitor<'a, 'b> { +impl<'de, 'b> de::MapAccess<'de> for MapVisitor<'de, 'b> { type Error = Error; - fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> - where K: de::DeserializeSeed, + fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> + where K: de::DeserializeSeed<'de>, { if self.cur_parent == self.max || self.cur == self.max { return Ok(None) @@ -268,11 +268,11 @@ impl<'a, 'b> de::MapVisitor for MapVisitor<'a, 'b> { let table = &mut self.tables[pos]; // If we're not yet at the appropriate depth for this table then we - // just visit the next portion of its header and then continue + // just next the next portion of its header and then continue // decoding. if self.depth != table.header.len() { let key = &table.header[self.depth]; - let key = seed.deserialize(StrDeserializer::new(key[..].into()))?; + let key = seed.deserialize(StrDeserializer::new(key.clone()))?; return Ok(Some(key)) } @@ -289,8 +289,8 @@ impl<'a, 'b> de::MapVisitor for MapVisitor<'a, 'b> { } } - fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error> - where V: de::DeserializeSeed, + fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error> + where V: de::DeserializeSeed<'de>, { if let Some((k, v)) = self.next_value.take() { match seed.deserialize(ValueDeserializer::new(v)) { @@ -323,11 +323,11 @@ impl<'a, 'b> de::MapVisitor for MapVisitor<'a, 'b> { } } -impl<'a, 'b> de::SeqVisitor for MapVisitor<'a, 'b> { +impl<'de, 'b> de::SeqAccess<'de> for MapVisitor<'de, 'b> { type Error = Error; - fn visit_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> - where K: de::DeserializeSeed, + fn next_element_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> + where K: de::DeserializeSeed<'de>, { assert!(self.next_value.is_none()); assert!(self.values.next().is_none()); @@ -361,11 +361,11 @@ impl<'a, 'b> de::SeqVisitor for MapVisitor<'a, 'b> { } } -impl<'a, 'b> de::Deserializer for MapVisitor<'a, 'b> { +impl<'de, 'b> de::Deserializer<'de> for MapVisitor<'de, 'b> { type Error = Error; - fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error> - where V: de::Visitor, + fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error> + where V: de::Visitor<'de>, { if self.array { visitor.visit_seq(self) @@ -377,15 +377,15 @@ impl<'a, 'b> de::Deserializer for MapVisitor<'a, 'b> { // `None` is interpreted as a missing field so be sure to implement `Some` // as a present field. fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error> - where V: de::Visitor + where V: de::Visitor<'de>, { visitor.visit_some(self) } - forward_to_deserialize! { + forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq - seq_fixed_size bytes byte_buf map struct unit newtype_struct - struct_field ignored_any unit_struct tuple_struct tuple enum + bytes byte_buf map struct unit newtype_struct identifier + ignored_any unit_struct tuple_struct tuple enum } } @@ -401,22 +401,22 @@ impl<'a> StrDeserializer<'a> { } } -impl<'a> de::Deserializer for StrDeserializer<'a> { +impl<'de> de::Deserializer<'de> for StrDeserializer<'de> { type Error = Error; - fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error> - where V: de::Visitor, + fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error> + where V: de::Visitor<'de>, { match self.key { - Cow::Borrowed(s) => visitor.visit_str(s), + Cow::Borrowed(s) => visitor.visit_borrowed_str(s), Cow::Owned(s) => visitor.visit_string(s), } } - forward_to_deserialize! { + forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq - seq_fixed_size bytes byte_buf map struct option unit newtype_struct - struct_field ignored_any unit_struct tuple_struct tuple enum + bytes byte_buf map struct option unit newtype_struct + ignored_any unit_struct tuple_struct tuple enum identifier } } @@ -432,17 +432,17 @@ impl<'a> ValueDeserializer<'a> { } } -impl<'a> de::Deserializer for ValueDeserializer<'a> { +impl<'de> de::Deserializer<'de> for ValueDeserializer<'de> { type Error = Error; - fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error> - where V: de::Visitor, + fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error> + where V: de::Visitor<'de>, { match self.value { Value::Integer(i) => visitor.visit_i64(i), Value::Boolean(b) => visitor.visit_bool(b), Value::Float(f) => visitor.visit_f64(f), - Value::String(Cow::Borrowed(s)) => visitor.visit_str(s), + Value::String(Cow::Borrowed(s)) => visitor.visit_borrowed_str(s), Value::String(Cow::Owned(s)) => visitor.visit_string(s), Value::Datetime(s) => visitor.visit_map(DatetimeDeserializer { date: s, @@ -467,7 +467,7 @@ impl<'a> de::Deserializer for ValueDeserializer<'a> { name: &'static str, fields: &'static [&'static str], visitor: V) -> Result<V::Value, Error> - where V: de::Visitor, + where V: de::Visitor<'de>, { if name == SERDE_STRUCT_NAME && fields == &[SERDE_STRUCT_FIELD_NAME] { if let Value::Datetime(s) = self.value { @@ -478,26 +478,26 @@ impl<'a> de::Deserializer for ValueDeserializer<'a> { } } - self.deserialize(visitor) + self.deserialize_any(visitor) } // `None` is interpreted as a missing field so be sure to implement `Some` // as a present field. fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error> - where V: de::Visitor + where V: de::Visitor<'de>, { visitor.visit_some(self) } - forward_to_deserialize! { + forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq - seq_fixed_size bytes byte_buf map unit newtype_struct - struct_field ignored_any unit_struct tuple_struct tuple enum + bytes byte_buf map unit newtype_struct identifier + ignored_any unit_struct tuple_struct tuple enum } } -impl<'a> de::value::ValueDeserializer<Error> for Value<'a> { - type Deserializer = ValueDeserializer<'a>; +impl<'de> de::IntoDeserializer<'de, Error> for Value<'de> { + type Deserializer = ValueDeserializer<'de>; fn into_deserializer(self) -> Self::Deserializer { ValueDeserializer::new(self) @@ -509,11 +509,11 @@ struct DatetimeDeserializer<'a> { date: &'a str, } -impl<'a> de::MapVisitor for DatetimeDeserializer<'a> { +impl<'de> de::MapAccess<'de> for DatetimeDeserializer<'de> { type Error = Error; - fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> - where K: de::DeserializeSeed, + fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> + where K: de::DeserializeSeed<'de>, { if self.visited { return Ok(None) @@ -522,8 +522,8 @@ impl<'a> de::MapVisitor for DatetimeDeserializer<'a> { seed.deserialize(DatetimeFieldDeserializer).map(Some) } - fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error> - where V: de::DeserializeSeed, + fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error> + where V: de::DeserializeSeed<'de>, { seed.deserialize(StrDeserializer::new(self.date.into())) } @@ -531,19 +531,19 @@ impl<'a> de::MapVisitor for DatetimeDeserializer<'a> { struct DatetimeFieldDeserializer; -impl de::Deserializer for DatetimeFieldDeserializer { +impl<'de> de::Deserializer<'de> for DatetimeFieldDeserializer { type Error = Error; - fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error> - where V: de::Visitor, + fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error> + where V: de::Visitor<'de>, { - visitor.visit_str(SERDE_STRUCT_FIELD_NAME) + visitor.visit_borrowed_str(SERDE_STRUCT_FIELD_NAME) } - forward_to_deserialize! { + forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq - seq_fixed_size bytes byte_buf map struct option unit newtype_struct - struct_field ignored_any unit_struct tuple_struct tuple enum + bytes byte_buf map struct option unit newtype_struct + ignored_any unit_struct tuple_struct tuple enum identifier } } @@ -552,11 +552,11 @@ struct InlineTableDeserializer<'a> { next_value: Option<Value<'a>>, } -impl<'a> de::MapVisitor for InlineTableDeserializer<'a> { +impl<'de> de::MapAccess<'de> for InlineTableDeserializer<'de> { type Error = Error; - fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> - where K: de::DeserializeSeed, + fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error> + where K: de::DeserializeSeed<'de>, { let (key, value) = match self.values.next() { Some(pair) => pair, @@ -566,8 +566,8 @@ impl<'a> de::MapVisitor for InlineTableDeserializer<'a> { seed.deserialize(StrDeserializer::new(key)).map(Some) } - fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error> - where V: de::DeserializeSeed, + fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error> + where V: de::DeserializeSeed<'de>, { let value = self.next_value.take().expect("Unable to read table values"); seed.deserialize(ValueDeserializer::new(value)) @@ -420,7 +420,7 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> { fn serialize_unit_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str) -> Result<(), Self::Error> { Err(Error::UnsupportedType) @@ -435,7 +435,7 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> { fn serialize_newtype_variant<T: ?Sized>(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _value: &T) -> Result<(), Self::Error> @@ -454,11 +454,6 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> { }) } - fn serialize_seq_fixed_size(self, size: usize) - -> Result<Self::SerializeSeq, Self::Error> { - self.serialize_seq(Some(size)) - } - fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> { Err(Error::UnsupportedType) @@ -471,7 +466,7 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> { fn serialize_tuple_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeTupleVariant, Self::Error> { @@ -507,7 +502,7 @@ impl<'a, 'b> ser::Serializer for &'b mut Serializer<'a> { fn serialize_struct_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeStructVariant, Self::Error> { @@ -754,7 +749,7 @@ impl<'a, 'b> ser::Serializer for DateStrEmitter<'a, 'b> { fn serialize_unit_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str) -> Result<(), Self::Error> { Err(Error::DateInvalid) @@ -769,7 +764,7 @@ impl<'a, 'b> ser::Serializer for DateStrEmitter<'a, 'b> { fn serialize_newtype_variant<T: ?Sized>(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _value: &T) -> Result<(), Self::Error> @@ -783,11 +778,6 @@ impl<'a, 'b> ser::Serializer for DateStrEmitter<'a, 'b> { Err(Error::DateInvalid) } - fn serialize_seq_fixed_size(self, _size: usize) - -> Result<Self::SerializeSeq, Self::Error> { - Err(Error::DateInvalid) - } - fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> { Err(Error::DateInvalid) @@ -800,7 +790,7 @@ impl<'a, 'b> ser::Serializer for DateStrEmitter<'a, 'b> { fn serialize_tuple_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeTupleVariant, Self::Error> { @@ -819,7 +809,7 @@ impl<'a, 'b> ser::Serializer for DateStrEmitter<'a, 'b> { fn serialize_struct_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeStructVariant, Self::Error> { @@ -918,7 +908,7 @@ impl ser::Serializer for StringExtractor { fn serialize_unit_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str) -> Result<String, Self::Error> { Err(Error::KeyNotString) @@ -933,7 +923,7 @@ impl ser::Serializer for StringExtractor { fn serialize_newtype_variant<T: ?Sized>(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _value: &T) -> Result<String, Self::Error> @@ -947,11 +937,6 @@ impl ser::Serializer for StringExtractor { Err(Error::KeyNotString) } - fn serialize_seq_fixed_size(self, _size: usize) - -> Result<Self::SerializeSeq, Self::Error> { - Err(Error::KeyNotString) - } - fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> { Err(Error::KeyNotString) @@ -964,7 +949,7 @@ impl ser::Serializer for StringExtractor { fn serialize_tuple_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeTupleVariant, Self::Error> { @@ -983,7 +968,7 @@ impl ser::Serializer for StringExtractor { fn serialize_struct_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeStructVariant, Self::Error> { @@ -1175,7 +1160,7 @@ impl<E: ser::Error> ser::Serializer for Categorize<E> { Err(ser::Error::custom("unsupported")) } - fn serialize_unit_variant(self, _: &'static str, _: usize, _: &'static str) -> Result<Self::Ok, Self::Error> { + fn serialize_unit_variant(self, _: &'static str, _: u32, _: &'static str) -> Result<Self::Ok, Self::Error> { Err(ser::Error::custom("unsupported")) } @@ -1183,7 +1168,7 @@ impl<E: ser::Error> ser::Serializer for Categorize<E> { v.serialize(self) } - fn serialize_newtype_variant<T: ?Sized + ser::Serialize>(self, _: &'static str, _: usize, _: &'static str, _: &T) -> Result<Self::Ok, Self::Error> { + fn serialize_newtype_variant<T: ?Sized + ser::Serialize>(self, _: &'static str, _: u32, _: &'static str, _: &T) -> Result<Self::Ok, Self::Error> { Err(ser::Error::custom("unsupported")) } @@ -1191,10 +1176,6 @@ impl<E: ser::Error> ser::Serializer for Categorize<E> { Ok(self) } - fn serialize_seq_fixed_size(self, _: usize) -> Result<Self, Self::Error> { - Ok(self) - } - fn serialize_tuple(self, _: usize) -> Result<Self::SerializeTuple, Self::Error> { Err(ser::Error::custom("unsupported")) } @@ -1203,7 +1184,7 @@ impl<E: ser::Error> ser::Serializer for Categorize<E> { Err(ser::Error::custom("unsupported")) } - fn serialize_tuple_variant(self, _: &'static str, _: usize, _: &'static str, _: usize) -> Result<Self::SerializeTupleVariant, Self::Error> { + fn serialize_tuple_variant(self, _: &'static str, _: u32, _: &'static str, _: usize) -> Result<Self::SerializeTupleVariant, Self::Error> { Err(ser::Error::custom("unsupported")) } @@ -1215,7 +1196,7 @@ impl<E: ser::Error> ser::Serializer for Categorize<E> { Ok(self) } - fn serialize_struct_variant(self, _: &'static str, _: usize, _: &'static str, _: usize) -> Result<Self::SerializeStructVariant, Self::Error> { + fn serialize_struct_variant(self, _: &'static str, _: u32, _: &'static str, _: usize) -> Result<Self::SerializeStructVariant, Self::Error> { Err(ser::Error::custom("unsupported")) } } diff --git a/src/value.rs b/src/value.rs index 5c59437..7c2b3eb 100644 --- a/src/value.rs +++ b/src/value.rs @@ -58,8 +58,8 @@ impl Value { /// something is wrong with the data, for example required struct fields are /// missing from the TOML map or some number is too big to fit in the expected /// primitive type. - pub fn try_into<T>(self) -> Result<T, ::de::Error> - where T: de::Deserialize, + pub fn try_into<'de, T>(self) -> Result<T, ::de::Error> + where T: de::Deserialize<'de>, { de::Deserialize::deserialize(self) } @@ -387,13 +387,13 @@ impl ser::Serialize for Value { } } -impl de::Deserialize for Value { +impl<'de> de::Deserialize<'de> for Value { fn deserialize<D>(deserializer: D) -> Result<Value, D::Error> - where D: de::Deserializer + where D: de::Deserializer<'de>, { struct ValueVisitor; - impl de::Visitor for ValueVisitor { + impl<'de> de::Visitor<'de> for ValueVisitor { type Value = Value; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { @@ -421,55 +421,58 @@ impl de::Deserialize for Value { } fn visit_some<D>(self, deserializer: D) -> Result<Value, D::Error> - where D: de::Deserializer, + where D: de::Deserializer<'de>, { de::Deserialize::deserialize(deserializer) } - fn visit_seq<V>(self, visitor: V) -> Result<Value, V::Error> - where V: de::SeqVisitor + fn visit_seq<V>(self, mut visitor: V) -> Result<Value, V::Error> + where V: de::SeqAccess<'de>, { - let values = de::impls::VecVisitor::new().visit_seq(visitor)?; - Ok(Value::Array(values)) + let mut vec = Vec::new(); + while let Some(elem) = try!(visitor.next_element()) { + vec.push(elem); + } + Ok(Value::Array(vec)) } fn visit_map<V>(self, mut visitor: V) -> Result<Value, V::Error> - where V: de::MapVisitor + where V: de::MapAccess<'de>, { let mut key = String::new(); - let datetime = visitor.visit_key_seed(DatetimeOrTable { + let datetime = visitor.next_key_seed(DatetimeOrTable { key: &mut key, })?; match datetime { Some(true) => { - let date: DatetimeFromString = visitor.visit_value()?; + let date: DatetimeFromString = visitor.next_value()?; return Ok(Value::Datetime(date.value)) } None => return Ok(Value::Table(BTreeMap::new())), Some(false) => {} } let mut map = BTreeMap::new(); - map.insert(key, visitor.visit_value()?); - while let Some(key) = visitor.visit_key()? { + map.insert(key, visitor.next_value()?); + while let Some(key) = visitor.next_key()? { if map.contains_key(&key) { let msg = format!("duplicate key: `{}`", key); return Err(de::Error::custom(msg)) } - map.insert(key, visitor.visit_value()?); + map.insert(key, visitor.next_value()?); } Ok(Value::Table(map)) } } - deserializer.deserialize(ValueVisitor) + deserializer.deserialize_any(ValueVisitor) } } -impl de::Deserializer for Value { +impl<'de> de::Deserializer<'de> for Value { type Error = ::de::Error; - fn deserialize<V>(self, visitor: V) -> Result<V::Value, ::de::Error> - where V: de::Visitor, + fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, ::de::Error> + where V: de::Visitor<'de>, { match self { Value::Boolean(v) => visitor.visit_bool(v), @@ -505,15 +508,15 @@ impl de::Deserializer for Value { // `None` is interpreted as a missing field so be sure to implement `Some` // as a present field. fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, ::de::Error> - where V: de::Visitor + where V: de::Visitor<'de>, { visitor.visit_some(self) } - forward_to_deserialize! { + forward_to_deserialize_any! { bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq - seq_fixed_size bytes byte_buf map unit_struct tuple_struct struct - struct_field tuple ignored_any enum newtype_struct + bytes byte_buf map unit_struct tuple_struct struct + tuple ignored_any enum newtype_struct identifier } } @@ -529,11 +532,12 @@ impl SeqDeserializer { } } -impl de::SeqVisitor for SeqDeserializer { +impl<'de> de::SeqAccess<'de> for SeqDeserializer { type Error = ::de::Error; - fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, ::de::Error> - where T: de::DeserializeSeed, + fn next_element_seed<T>(&mut self, seed: T) + -> Result<Option<T::Value>, ::de::Error> + where T: de::DeserializeSeed<'de>, { match self.iter.next() { Some(value) => seed.deserialize(value).map(Some), @@ -541,8 +545,11 @@ impl de::SeqVisitor for SeqDeserializer { } } - fn size_hint(&self) -> (usize, Option<usize>) { - self.iter.size_hint() + fn size_hint(&self) -> Option<usize> { + match self.iter.size_hint() { + (lower, Some(upper)) if lower == upper => Some(upper), + _ => None, + } } } @@ -560,11 +567,11 @@ impl MapDeserializer { } } -impl de::MapVisitor for MapDeserializer { +impl<'de> de::MapAccess<'de> for MapDeserializer { type Error = ::de::Error; - fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, ::de::Error> - where T: de::DeserializeSeed, + fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, ::de::Error> + where T: de::DeserializeSeed<'de>, { match self.iter.next() { Some((key, value)) => { @@ -575,8 +582,8 @@ impl de::MapVisitor for MapDeserializer { } } - fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, ::de::Error> - where T: de::DeserializeSeed, + fn next_value_seed<T>(&mut self, seed: T) -> Result<T::Value, ::de::Error> + where T: de::DeserializeSeed<'de>, { let (key, res) = match self.value.take() { Some((key, value)) => (key, seed.deserialize(value)), @@ -588,8 +595,11 @@ impl de::MapVisitor for MapDeserializer { }) } - fn size_hint(&self) -> (usize, Option<usize>) { - self.iter.size_hint() + fn size_hint(&self) -> Option<usize> { + match self.iter.size_hint() { + (lower, Some(upper)) if lower == upper => Some(upper), + _ => None, + } } } @@ -681,7 +691,7 @@ impl ser::Serializer for Serializer { fn serialize_unit_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str) -> Result<Value, ::ser::Error> { Err(::ser::Error::UnsupportedType) @@ -698,7 +708,7 @@ impl ser::Serializer for Serializer { fn serialize_newtype_variant<T: ?Sized>(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _value: &T) -> Result<Value, ::ser::Error> @@ -725,11 +735,6 @@ impl ser::Serializer for Serializer { }) } - fn serialize_seq_fixed_size(self, size: usize) - -> Result<Self::SerializeSeq, ::ser::Error> { - self.serialize_seq(Some(size)) - } - fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, ::ser::Error> { Err(::ser::Error::UnsupportedType) } @@ -741,7 +746,7 @@ impl ser::Serializer for Serializer { fn serialize_tuple_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeTupleVariant, ::ser::Error> @@ -765,7 +770,7 @@ impl ser::Serializer for Serializer { fn serialize_struct_variant(self, _name: &'static str, - _variant_index: usize, + _variant_index: u32, _variant: &'static str, _len: usize) -> Result<Self::SerializeStructVariant, ::ser::Error> @@ -851,17 +856,17 @@ struct DatetimeOrTable<'a> { key: &'a mut String, } -impl<'a> de::DeserializeSeed for DatetimeOrTable<'a> { +impl<'a, 'de> de::DeserializeSeed<'de> for DatetimeOrTable<'a> { type Value = bool; fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error> - where D: de::Deserializer + where D: de::Deserializer<'de> { - deserializer.deserialize(self) + deserializer.deserialize_any(self) } } -impl<'a> de::Visitor for DatetimeOrTable<'a> { +impl<'a, 'de> de::Visitor<'de> for DatetimeOrTable<'a> { type Value = bool; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |