Merge pull request #826 from serde-rs/lifetime
Add a 'de lifetime to the deserialize traits
This commit is contained in:
commit
3d3118f8b0
@ -29,7 +29,7 @@ unstable-testing = ["unstable", "std"]
|
||||
playground = ["serde_derive"]
|
||||
|
||||
[dependencies]
|
||||
serde_derive = { version = "0.9", optional = true }
|
||||
serde_derive = { version = "0.9", optional = true, path = "../serde_derive" }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_derive = "0.9"
|
||||
serde_derive = { version = "0.9", path = "../serde_derive" }
|
||||
|
@ -237,7 +237,7 @@ mod bytebuf {
|
||||
/// This type implements the `serde::de::Visitor` trait for a `ByteBuf`.
|
||||
pub struct ByteBufVisitor;
|
||||
|
||||
impl de::Visitor for ByteBufVisitor {
|
||||
impl<'de> de::Visitor<'de> for ByteBufVisitor {
|
||||
type Value = ByteBuf;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -253,7 +253,7 @@ mod bytebuf {
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<ByteBuf, V::Error>
|
||||
where V: de::SeqVisitor
|
||||
where V: de::SeqVisitor<'de>
|
||||
{
|
||||
let len = cmp::min(visitor.size_hint().0, 4096);
|
||||
let mut values = Vec::with_capacity(len);
|
||||
@ -292,10 +292,10 @@ mod bytebuf {
|
||||
}
|
||||
}
|
||||
|
||||
impl de::Deserialize for ByteBuf {
|
||||
impl<'de> de::Deserialize<'de> for ByteBuf {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<ByteBuf, D::Error>
|
||||
where D: de::Deserializer
|
||||
where D: de::Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_byte_buf(ByteBufVisitor)
|
||||
}
|
||||
|
@ -83,8 +83,10 @@ impl Content {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for Content {
|
||||
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
|
||||
impl<'de> Deserialize<'de> for Content {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
// Untagged and internally tagged enums are only supported in
|
||||
// self-describing formats.
|
||||
deserializer.deserialize(ContentVisitor)
|
||||
@ -93,7 +95,7 @@ impl Deserialize for Content {
|
||||
|
||||
struct ContentVisitor;
|
||||
|
||||
impl Visitor for ContentVisitor {
|
||||
impl<'de> Visitor<'de> for ContentVisitor {
|
||||
type Value = Content;
|
||||
|
||||
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -209,19 +211,19 @@ impl Visitor for ContentVisitor {
|
||||
}
|
||||
|
||||
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
Deserialize::deserialize(deserializer).map(|v| Content::Some(Box::new(v)))
|
||||
}
|
||||
|
||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
Deserialize::deserialize(deserializer).map(|v| Content::Newtype(Box::new(v)))
|
||||
}
|
||||
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: SeqVisitor
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
|
||||
while let Some(e) = try!(visitor.visit()) {
|
||||
@ -231,7 +233,7 @@ impl Visitor for ContentVisitor {
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapVisitor<'de>
|
||||
{
|
||||
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
|
||||
while let Some(kv) = try!(visitor.visit()) {
|
||||
@ -241,7 +243,7 @@ impl Visitor for ContentVisitor {
|
||||
}
|
||||
|
||||
fn visit_enum<V>(self, _visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: EnumVisitor
|
||||
where V: EnumVisitor<'de>
|
||||
{
|
||||
Err(de::Error::custom("untagged and internally tagged enums do not support enum input"))
|
||||
}
|
||||
@ -265,11 +267,11 @@ impl TagOrContentVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl DeserializeSeed for TagOrContentVisitor {
|
||||
impl<'de> DeserializeSeed<'de> for TagOrContentVisitor {
|
||||
type Value = TagOrContent;
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
// Internally tagged enums are only supported in self-describing
|
||||
// formats.
|
||||
@ -277,7 +279,7 @@ impl DeserializeSeed for TagOrContentVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl Visitor for TagOrContentVisitor {
|
||||
impl<'de> Visitor<'de> for TagOrContentVisitor {
|
||||
type Value = TagOrContent;
|
||||
|
||||
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -409,31 +411,31 @@ impl Visitor for TagOrContentVisitor {
|
||||
}
|
||||
|
||||
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
ContentVisitor.visit_some(deserializer).map(TagOrContent::Content)
|
||||
}
|
||||
|
||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
ContentVisitor.visit_newtype_struct(deserializer).map(TagOrContent::Content)
|
||||
}
|
||||
|
||||
fn visit_seq<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: SeqVisitor
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
ContentVisitor.visit_seq(visitor).map(TagOrContent::Content)
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapVisitor<'de>
|
||||
{
|
||||
ContentVisitor.visit_map(visitor).map(TagOrContent::Content)
|
||||
}
|
||||
|
||||
fn visit_enum<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: EnumVisitor
|
||||
where V: EnumVisitor<'de>
|
||||
{
|
||||
ContentVisitor.visit_enum(visitor).map(TagOrContent::Content)
|
||||
}
|
||||
@ -464,13 +466,13 @@ impl<T> TaggedContentVisitor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DeserializeSeed for TaggedContentVisitor<T>
|
||||
where T: Deserialize
|
||||
impl<'de, T> DeserializeSeed<'de> for TaggedContentVisitor<T>
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
type Value = TaggedContent<T>;
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
// Internally tagged enums are only supported in self-describing
|
||||
// formats.
|
||||
@ -478,8 +480,8 @@ impl<T> DeserializeSeed for TaggedContentVisitor<T>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Visitor for TaggedContentVisitor<T>
|
||||
where T: Deserialize
|
||||
impl<'de, T> Visitor<'de> for TaggedContentVisitor<T>
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
type Value = TaggedContent<T>;
|
||||
|
||||
@ -488,7 +490,7 @@ impl<T> Visitor for TaggedContentVisitor<T>
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapVisitor<'de>
|
||||
{
|
||||
let mut tag = None;
|
||||
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
|
||||
@ -532,17 +534,17 @@ pub struct TagOrContentFieldVisitor {
|
||||
pub content: &'static str,
|
||||
}
|
||||
|
||||
impl DeserializeSeed for TagOrContentFieldVisitor {
|
||||
impl<'de> DeserializeSeed<'de> for TagOrContentFieldVisitor {
|
||||
type Value = TagOrContentField;
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Visitor for TagOrContentFieldVisitor {
|
||||
impl<'de> Visitor<'de> for TagOrContentFieldVisitor {
|
||||
type Value = TagOrContentField;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -570,13 +572,13 @@ pub struct ContentDeserializer<E> {
|
||||
|
||||
/// Used when deserializing an internally tagged enum because the content will
|
||||
/// be used exactly once.
|
||||
impl<E> Deserializer for ContentDeserializer<E>
|
||||
impl<'de, E> Deserializer<'de> for ContentDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.content {
|
||||
Content::Bool(v) => visitor.visit_bool(v),
|
||||
@ -618,7 +620,7 @@ impl<E> Deserializer for ContentDeserializer<E>
|
||||
}
|
||||
|
||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.content {
|
||||
Content::None => visitor.visit_none(),
|
||||
@ -629,7 +631,7 @@ impl<E> Deserializer for ContentDeserializer<E>
|
||||
}
|
||||
|
||||
fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
visitor.visit_newtype_struct(self)
|
||||
}
|
||||
@ -639,7 +641,7 @@ impl<E> Deserializer for ContentDeserializer<E>
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
let (variant, value) = match self.content {
|
||||
Content::Map(value) => {
|
||||
@ -696,7 +698,7 @@ struct EnumDeserializer<E>
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> de::EnumVisitor for EnumDeserializer<E>
|
||||
impl<'de, E> de::EnumVisitor<'de> for EnumDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
@ -705,7 +707,7 @@ impl<E> de::EnumVisitor for EnumDeserializer<E>
|
||||
fn visit_variant_seed<V>(self,
|
||||
seed: V)
|
||||
-> Result<(V::Value, VariantDeserializer<E>), Self::Error>
|
||||
where V: de::DeserializeSeed
|
||||
where V: de::DeserializeSeed<'de>
|
||||
{
|
||||
let visitor = VariantDeserializer {
|
||||
value: self.value,
|
||||
@ -722,7 +724,7 @@ struct VariantDeserializer<E>
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> de::VariantVisitor for VariantDeserializer<E>
|
||||
impl<'de, E> de::VariantVisitor<'de> for VariantDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
@ -735,7 +737,7 @@ impl<E> de::VariantVisitor for VariantDeserializer<E>
|
||||
}
|
||||
|
||||
fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, E>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.value {
|
||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)),
|
||||
@ -744,7 +746,7 @@ impl<E> de::VariantVisitor for VariantDeserializer<E>
|
||||
}
|
||||
|
||||
fn visit_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
match self.value {
|
||||
Some(Content::Seq(v)) => {
|
||||
@ -759,7 +761,7 @@ impl<E> de::VariantVisitor for VariantDeserializer<E>
|
||||
_fields: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
match self.value {
|
||||
Some(Content::Map(v)) => {
|
||||
@ -789,14 +791,14 @@ impl<E> SeqDeserializer<E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::Deserializer for SeqDeserializer<E>
|
||||
impl<'de, E> de::Deserializer<'de> for SeqDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
#[inline]
|
||||
fn deserialize<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
let len = self.iter.len();
|
||||
if len == 0 {
|
||||
@ -819,13 +821,13 @@ impl<E> de::Deserializer for SeqDeserializer<E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::SeqVisitor for SeqDeserializer<E>
|
||||
impl<'de, E> de::SeqVisitor<'de> for SeqDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)).map(Some),
|
||||
@ -858,13 +860,13 @@ impl<E> MapDeserializer<E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::MapVisitor for MapDeserializer<E>
|
||||
impl<'de, E> de::MapVisitor<'de> for MapDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some((key, value)) => {
|
||||
@ -876,7 +878,7 @@ impl<E> de::MapVisitor for MapDeserializer<E>
|
||||
}
|
||||
|
||||
fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.value.take() {
|
||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)),
|
||||
@ -889,14 +891,14 @@ impl<E> de::MapVisitor for MapDeserializer<E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::Deserializer for MapDeserializer<E>
|
||||
impl<'de, E> de::Deserializer<'de> for MapDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
#[inline]
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_map(self)
|
||||
}
|
||||
@ -917,13 +919,13 @@ pub struct ContentRefDeserializer<'a, E> {
|
||||
|
||||
/// Used when deserializing an untagged enum because the content may need to be
|
||||
/// used more than once.
|
||||
impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||
impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, E>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match *self.content {
|
||||
Content::Bool(v) => visitor.visit_bool(v),
|
||||
@ -965,7 +967,7 @@ impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||
}
|
||||
|
||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, E>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match *self.content {
|
||||
Content::None => visitor.visit_none(),
|
||||
@ -976,7 +978,7 @@ impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||
}
|
||||
|
||||
fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, E>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
visitor.visit_newtype_struct(self)
|
||||
}
|
||||
@ -986,7 +988,7 @@ impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
let (variant, value) = match *self.content {
|
||||
Content::Map(ref value) => {
|
||||
@ -1043,14 +1045,14 @@ struct EnumRefDeserializer<'a, E>
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, E> de::EnumVisitor for EnumRefDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::EnumVisitor<'de> for EnumRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
type Variant = VariantRefDeserializer<'a, Self::Error>;
|
||||
|
||||
fn visit_variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error>
|
||||
where V: de::DeserializeSeed
|
||||
where V: de::DeserializeSeed<'de>
|
||||
{
|
||||
let visitor = VariantRefDeserializer {
|
||||
value: self.value,
|
||||
@ -1067,7 +1069,7 @@ struct VariantRefDeserializer<'a, E>
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::VariantVisitor<'de> for VariantRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
@ -1080,7 +1082,7 @@ impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E>
|
||||
}
|
||||
|
||||
fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, E>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.value {
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)),
|
||||
@ -1089,7 +1091,7 @@ impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E>
|
||||
}
|
||||
|
||||
fn visit_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
match self.value {
|
||||
Some(&Content::Seq(ref v)) => {
|
||||
@ -1104,7 +1106,7 @@ impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E>
|
||||
_fields: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
match self.value {
|
||||
Some(&Content::Map(ref v)) => {
|
||||
@ -1134,14 +1136,14 @@ impl<'a, E> SeqRefDeserializer<'a, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::Deserializer for SeqRefDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::Deserializer<'de> for SeqRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
#[inline]
|
||||
fn deserialize<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
let len = self.iter.len();
|
||||
if len == 0 {
|
||||
@ -1164,13 +1166,13 @@ impl<'a, E> de::Deserializer for SeqRefDeserializer<'a, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::SeqVisitor for SeqRefDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::SeqVisitor<'de> for SeqRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)).map(Some),
|
||||
@ -1203,13 +1205,13 @@ impl<'a, E> MapRefDeserializer<'a, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::MapVisitor for MapRefDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::MapVisitor<'de> for MapRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(&(ref key, ref value)) => {
|
||||
@ -1221,7 +1223,7 @@ impl<'a, E> de::MapVisitor for MapRefDeserializer<'a, E>
|
||||
}
|
||||
|
||||
fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.value.take() {
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)),
|
||||
@ -1234,14 +1236,14 @@ impl<'a, E> de::MapVisitor for MapRefDeserializer<'a, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::Deserializer for MapRefDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::Deserializer<'de> for MapRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
#[inline]
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_map(self)
|
||||
}
|
||||
@ -1253,7 +1255,7 @@ impl<'a, E> de::Deserializer for MapRefDeserializer<'a, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::value::ValueDeserializer<E> for ContentDeserializer<E>
|
||||
impl<'de, E> de::value::ValueDeserializer<'de, E> for ContentDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = Self;
|
||||
@ -1263,7 +1265,7 @@ impl<E> de::value::ValueDeserializer<E> for ContentDeserializer<E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::value::ValueDeserializer<E> for ContentRefDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::value::ValueDeserializer<'de, E> for ContentRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = Self;
|
||||
@ -1291,7 +1293,7 @@ impl<'a> InternallyTaggedUnitVisitor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Visitor for InternallyTaggedUnitVisitor<'a> {
|
||||
impl<'de, 'a> Visitor<'de> for InternallyTaggedUnitVisitor<'a> {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -1299,7 +1301,7 @@ impl<'a> Visitor for InternallyTaggedUnitVisitor<'a> {
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, _: V) -> Result<(), V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapVisitor<'de>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
@ -1323,7 +1325,7 @@ impl<'a> UntaggedUnitVisitor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Visitor for UntaggedUnitVisitor<'a> {
|
||||
impl<'de, 'a> Visitor<'de> for UntaggedUnitVisitor<'a> {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -68,7 +68,7 @@ use bytes::ByteBuf;
|
||||
/// A visitor that produces a `()`.
|
||||
pub struct UnitVisitor;
|
||||
|
||||
impl Visitor for UnitVisitor {
|
||||
impl<'de> Visitor<'de> for UnitVisitor {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -82,15 +82,15 @@ impl Visitor for UnitVisitor {
|
||||
}
|
||||
|
||||
fn visit_seq<V>(self, _: V) -> Result<(), V::Error>
|
||||
where V: SeqVisitor
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for () {
|
||||
impl<'de> Deserialize<'de> for () {
|
||||
fn deserialize<D>(deserializer: D) -> Result<(), D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_unit(UnitVisitor)
|
||||
}
|
||||
@ -101,7 +101,7 @@ impl Deserialize for () {
|
||||
/// A visitor that produces a `bool`.
|
||||
pub struct BoolVisitor;
|
||||
|
||||
impl Visitor for BoolVisitor {
|
||||
impl<'de> Visitor<'de> for BoolVisitor {
|
||||
type Value = bool;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -125,9 +125,9 @@ impl Visitor for BoolVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for bool {
|
||||
impl<'de> Deserialize<'de> for bool {
|
||||
fn deserialize<D>(deserializer: D) -> Result<bool, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_bool(BoolVisitor)
|
||||
}
|
||||
@ -151,14 +151,14 @@ macro_rules! impl_deserialize_num_method {
|
||||
|
||||
macro_rules! impl_deserialize_num {
|
||||
($ty:ident, $method:ident) => {
|
||||
impl Deserialize for $ty {
|
||||
impl<'de> Deserialize<'de> for $ty {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<$ty, D::Error>
|
||||
where D: Deserializer,
|
||||
where D: Deserializer<'de>,
|
||||
{
|
||||
struct PrimitiveVisitor;
|
||||
|
||||
impl Visitor for PrimitiveVisitor {
|
||||
impl<'de> Visitor<'de> for PrimitiveVisitor {
|
||||
type Value = $ty;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -209,7 +209,7 @@ impl_deserialize_num!(f64, deserialize_f64);
|
||||
|
||||
struct CharVisitor;
|
||||
|
||||
impl Visitor for CharVisitor {
|
||||
impl<'de> Visitor<'de> for CharVisitor {
|
||||
type Value = char;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -235,10 +235,10 @@ impl Visitor for CharVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for char {
|
||||
impl<'de> Deserialize<'de> for char {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<char, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_char(CharVisitor)
|
||||
}
|
||||
@ -250,7 +250,7 @@ impl Deserialize for char {
|
||||
struct StringVisitor;
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl Visitor for StringVisitor {
|
||||
impl<'de> Visitor<'de> for StringVisitor {
|
||||
type Value = String;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -295,9 +295,9 @@ impl Visitor for StringVisitor {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl Deserialize for String {
|
||||
impl<'de> Deserialize<'de> for String {
|
||||
fn deserialize<D>(deserializer: D) -> Result<String, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_string(StringVisitor)
|
||||
}
|
||||
@ -306,9 +306,9 @@ impl Deserialize for String {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(all(feature = "std", feature="unstable"))]
|
||||
impl Deserialize for Box<CStr> {
|
||||
impl<'de> Deserialize<'de> for Box<CStr> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let s = try!(CString::deserialize(deserializer));
|
||||
Ok(s.into_boxed_c_str())
|
||||
@ -316,9 +316,9 @@ impl Deserialize for Box<CStr> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for CString {
|
||||
impl<'de> Deserialize<'de> for CString {
|
||||
fn deserialize<D>(deserializer: D) -> Result<CString, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let bytes = try!(ByteBuf::deserialize(deserializer));
|
||||
CString::new(bytes).map_err(Error::custom)
|
||||
@ -331,7 +331,9 @@ struct OptionVisitor<T> {
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: Deserialize> Visitor for OptionVisitor<T> {
|
||||
impl<'de, T> Visitor<'de> for OptionVisitor<T>
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
type Value = Option<T>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -354,17 +356,17 @@ impl<T: Deserialize> Visitor for OptionVisitor<T> {
|
||||
|
||||
#[inline]
|
||||
fn visit_some<D>(self, deserializer: D) -> Result<Option<T>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
Ok(Some(try!(Deserialize::deserialize(deserializer))))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deserialize for Option<T>
|
||||
where T: Deserialize
|
||||
impl<'de, T> Deserialize<'de> for Option<T>
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<Option<T>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_option(OptionVisitor { marker: PhantomData })
|
||||
}
|
||||
@ -377,7 +379,7 @@ pub struct PhantomDataVisitor<T> {
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> Visitor for PhantomDataVisitor<T> {
|
||||
impl<'de, T> Visitor<'de> for PhantomDataVisitor<T> {
|
||||
type Value = PhantomData<T>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -392,9 +394,9 @@ impl<T> Visitor for PhantomDataVisitor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deserialize for PhantomData<T> {
|
||||
impl<'de, T> Deserialize<'de> for PhantomData<T> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<PhantomData<T>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let visitor = PhantomDataVisitor { marker: PhantomData };
|
||||
deserializer.deserialize_unit_struct("PhantomData", visitor)
|
||||
@ -405,21 +407,19 @@ impl<T> Deserialize for PhantomData<T> {
|
||||
|
||||
macro_rules! seq_impl {
|
||||
(
|
||||
$ty:ty,
|
||||
$visitor_ty:ident < $($typaram:ident : $bound1:ident $(+ $bound2:ident)*),* >,
|
||||
$ty:ident < T $(, $typaram:ident)* >,
|
||||
$visitor_ty:ident $( < $($boundparam:ident : $bound1:ident $(+ $bound2:ident)*),* > )*,
|
||||
$visitor:ident,
|
||||
$ctor:expr,
|
||||
$with_capacity:expr,
|
||||
$insert:expr
|
||||
) => {
|
||||
/// A visitor that produces a sequence.
|
||||
pub struct $visitor_ty<$($typaram),*> {
|
||||
marker: PhantomData<$ty>,
|
||||
pub struct $visitor_ty<T $(, $typaram)*> {
|
||||
marker: PhantomData<$ty<T $(, $typaram)*>>,
|
||||
}
|
||||
|
||||
impl<$($typaram),*> $visitor_ty<$($typaram),*>
|
||||
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||
{
|
||||
impl<T $(, $typaram),*> $visitor_ty<T $(, $typaram)*> {
|
||||
/// Construct a new sequence visitor.
|
||||
pub fn new() -> Self {
|
||||
$visitor_ty {
|
||||
@ -428,25 +428,26 @@ macro_rules! seq_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($typaram),*> Visitor for $visitor_ty<$($typaram),*>
|
||||
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||
impl<'de, T $(, $typaram)*> Visitor<'de> for $visitor_ty<T $(, $typaram)*>
|
||||
where T: Deserialize<'de>,
|
||||
$($($boundparam: $bound1 $(+ $bound2)*),*)*
|
||||
{
|
||||
type Value = $ty;
|
||||
type Value = $ty<T $(, $typaram)*>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a sequence")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_unit<E>(self) -> Result<$ty, E>
|
||||
fn visit_unit<E>(self) -> Result<Self::Value, E>
|
||||
where E: Error,
|
||||
{
|
||||
Ok($ctor)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<V>(self, mut $visitor: V) -> Result<$ty, V::Error>
|
||||
where V: SeqVisitor,
|
||||
fn visit_seq<V>(self, mut $visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: SeqVisitor<'de>,
|
||||
{
|
||||
let mut values = $with_capacity;
|
||||
|
||||
@ -458,11 +459,12 @@ macro_rules! seq_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($typaram),*> Deserialize for $ty
|
||||
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||
impl<'de, T $(, $typaram)*> Deserialize<'de> for $ty<T $(, $typaram)*>
|
||||
where T: Deserialize<'de>,
|
||||
$($($boundparam: $bound1 $(+ $bound2)*),*)*
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<$ty, D::Error>
|
||||
where D: Deserializer,
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_seq($visitor_ty::new())
|
||||
}
|
||||
@ -473,7 +475,7 @@ macro_rules! seq_impl {
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
seq_impl!(
|
||||
BinaryHeap<T>,
|
||||
BinaryHeapVisitor<T: Deserialize + Ord>,
|
||||
BinaryHeapVisitor<T: Ord>,
|
||||
visitor,
|
||||
BinaryHeap::new(),
|
||||
BinaryHeap::with_capacity(cmp::min(visitor.size_hint().0, 4096)),
|
||||
@ -482,7 +484,7 @@ seq_impl!(
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
seq_impl!(
|
||||
BTreeSet<T>,
|
||||
BTreeSetVisitor<T: Deserialize + Eq + Ord>,
|
||||
BTreeSetVisitor<T: Eq + Ord>,
|
||||
visitor,
|
||||
BTreeSet::new(),
|
||||
BTreeSet::new(),
|
||||
@ -491,7 +493,7 @@ seq_impl!(
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
seq_impl!(
|
||||
LinkedList<T>,
|
||||
LinkedListVisitor<T: Deserialize>,
|
||||
LinkedListVisitor,
|
||||
visitor,
|
||||
LinkedList::new(),
|
||||
LinkedList::new(),
|
||||
@ -500,7 +502,7 @@ seq_impl!(
|
||||
#[cfg(feature = "std")]
|
||||
seq_impl!(
|
||||
HashSet<T, S>,
|
||||
HashSetVisitor<T: Deserialize + Eq + Hash,
|
||||
HashSetVisitor<T: Eq + Hash,
|
||||
S: BuildHasher + Default>,
|
||||
visitor,
|
||||
HashSet::with_hasher(S::default()),
|
||||
@ -510,7 +512,7 @@ seq_impl!(
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
seq_impl!(
|
||||
Vec<T>,
|
||||
VecVisitor<T: Deserialize>,
|
||||
VecVisitor,
|
||||
visitor,
|
||||
Vec::new(),
|
||||
Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096)),
|
||||
@ -519,7 +521,7 @@ seq_impl!(
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
seq_impl!(
|
||||
VecDeque<T>,
|
||||
VecDequeVisitor<T: Deserialize>,
|
||||
VecDequeVisitor,
|
||||
visitor,
|
||||
VecDeque::new(),
|
||||
VecDeque::with_capacity(cmp::min(visitor.size_hint().0, 4096)),
|
||||
@ -537,8 +539,8 @@ impl<A> ArrayVisitor<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Visitor for ArrayVisitor<[T; 0]>
|
||||
where T: Deserialize
|
||||
impl<'de, T> Visitor<'de> for ArrayVisitor<[T; 0]>
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
type Value = [T; 0];
|
||||
|
||||
@ -555,17 +557,17 @@ impl<T> Visitor for ArrayVisitor<[T; 0]>
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<V>(self, _: V) -> Result<[T; 0], V::Error>
|
||||
where V: SeqVisitor
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
Ok([])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deserialize for [T; 0]
|
||||
where T: Deserialize
|
||||
impl<'de, T> Deserialize<'de> for [T; 0]
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<[T; 0], D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_seq_fixed_size(0, ArrayVisitor::<[T; 0]>::new())
|
||||
}
|
||||
@ -574,7 +576,9 @@ impl<T> Deserialize for [T; 0]
|
||||
macro_rules! array_impls {
|
||||
($($len:expr => ($($n:tt $name:ident)+))+) => {
|
||||
$(
|
||||
impl<T> Visitor for ArrayVisitor<[T; $len]> where T: Deserialize {
|
||||
impl<'de, T> Visitor<'de> for ArrayVisitor<[T; $len]>
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
type Value = [T; $len];
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -583,7 +587,7 @@ macro_rules! array_impls {
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<[T; $len], V::Error>
|
||||
where V: SeqVisitor,
|
||||
where V: SeqVisitor<'de>,
|
||||
{
|
||||
$(
|
||||
let $name = match try!(visitor.visit()) {
|
||||
@ -596,11 +600,11 @@ macro_rules! array_impls {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deserialize for [T; $len]
|
||||
where T: Deserialize,
|
||||
impl<'de, T> Deserialize<'de> for [T; $len]
|
||||
where T: Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<[T; $len], D::Error>
|
||||
where D: Deserializer,
|
||||
where D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_seq_fixed_size($len, ArrayVisitor::<[T; $len]>::new())
|
||||
}
|
||||
@ -654,14 +658,14 @@ macro_rules! tuple_impls {
|
||||
marker: PhantomData<($($name,)+)>,
|
||||
}
|
||||
|
||||
impl<$($name: Deserialize,)+> $visitor<$($name,)+> {
|
||||
impl<$($name,)+> $visitor<$($name,)+> {
|
||||
/// Construct a `TupleVisitor*<T>`.
|
||||
pub fn new() -> Self {
|
||||
$visitor { marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($name: Deserialize),+> Visitor for $visitor<$($name,)+> {
|
||||
impl<'de, $($name: Deserialize<'de>),+> Visitor<'de> for $visitor<$($name,)+> {
|
||||
type Value = ($($name,)+);
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -671,7 +675,7 @@ macro_rules! tuple_impls {
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<($($name,)+), V::Error>
|
||||
where V: SeqVisitor,
|
||||
where V: SeqVisitor<'de>,
|
||||
{
|
||||
$(
|
||||
let $name = match try!(visitor.visit()) {
|
||||
@ -684,10 +688,10 @@ macro_rules! tuple_impls {
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($name: Deserialize),+> Deserialize for ($($name,)+) {
|
||||
impl<'de, $($name: Deserialize<'de>),+> Deserialize<'de> for ($($name,)+) {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<($($name,)+), D::Error>
|
||||
where D: Deserializer,
|
||||
where D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_tuple($len, $visitor::new())
|
||||
}
|
||||
@ -719,20 +723,18 @@ tuple_impls! {
|
||||
|
||||
macro_rules! map_impl {
|
||||
(
|
||||
$ty:ty,
|
||||
$visitor_ty:ident < $($typaram:ident : $bound1:ident $(+ $bound2:ident)*),* >,
|
||||
$ty:ident < K, V $(, $typaram:ident)* >,
|
||||
$visitor_ty:ident < $($boundparam:ident : $bound1:ident $(+ $bound2:ident)*),* >,
|
||||
$visitor:ident,
|
||||
$ctor:expr,
|
||||
$with_capacity:expr
|
||||
) => {
|
||||
/// A visitor that produces a map.
|
||||
pub struct $visitor_ty<$($typaram),*> {
|
||||
marker: PhantomData<$ty>,
|
||||
pub struct $visitor_ty<K, V $(, $typaram)*> {
|
||||
marker: PhantomData<$ty<K, V $(, $typaram)*>>,
|
||||
}
|
||||
|
||||
impl<$($typaram),*> $visitor_ty<$($typaram),*>
|
||||
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||
{
|
||||
impl<K, V $(, $typaram)*> $visitor_ty<K, V $(, $typaram)*> {
|
||||
/// Construct a `MapVisitor*<T>`.
|
||||
pub fn new() -> Self {
|
||||
$visitor_ty {
|
||||
@ -741,25 +743,27 @@ macro_rules! map_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($typaram),*> Visitor for $visitor_ty<$($typaram),*>
|
||||
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||
impl<'de, K, V $(, $typaram)*> Visitor<'de> for $visitor_ty<K, V $(, $typaram)*>
|
||||
where K: Deserialize<'de>,
|
||||
V: Deserialize<'de>,
|
||||
$($boundparam: $bound1 $(+ $bound2)*),*
|
||||
{
|
||||
type Value = $ty;
|
||||
type Value = $ty<K, V $(, $typaram)*>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a map")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_unit<E>(self) -> Result<$ty, E>
|
||||
fn visit_unit<E>(self) -> Result<Self::Value, E>
|
||||
where E: Error,
|
||||
{
|
||||
Ok($ctor)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_map<Visitor>(self, mut $visitor: Visitor) -> Result<$ty, Visitor::Error>
|
||||
where Visitor: MapVisitor,
|
||||
fn visit_map<Visitor>(self, mut $visitor: Visitor) -> Result<Self::Value, Visitor::Error>
|
||||
where Visitor: MapVisitor<'de>,
|
||||
{
|
||||
let mut values = $with_capacity;
|
||||
|
||||
@ -771,11 +775,13 @@ macro_rules! map_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($typaram),*> Deserialize for $ty
|
||||
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||
impl<'de, K, V $(, $typaram)*> Deserialize<'de> for $ty<K, V $(, $typaram)*>
|
||||
where K: Deserialize<'de>,
|
||||
V: Deserialize<'de>,
|
||||
$($boundparam: $bound1 $(+ $bound2)*),*
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<$ty, D::Error>
|
||||
where D: Deserializer,
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_map($visitor_ty::new())
|
||||
}
|
||||
@ -786,8 +792,7 @@ macro_rules! map_impl {
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
map_impl!(
|
||||
BTreeMap<K, V>,
|
||||
BTreeMapVisitor<K: Deserialize + Ord,
|
||||
V: Deserialize>,
|
||||
BTreeMapVisitor<K: Ord>,
|
||||
visitor,
|
||||
BTreeMap::new(),
|
||||
BTreeMap::new());
|
||||
@ -795,8 +800,7 @@ map_impl!(
|
||||
#[cfg(feature = "std")]
|
||||
map_impl!(
|
||||
HashMap<K, V, S>,
|
||||
HashMapVisitor<K: Deserialize + Eq + Hash,
|
||||
V: Deserialize,
|
||||
HashMapVisitor<K: Eq + Hash,
|
||||
S: BuildHasher + Default>,
|
||||
visitor,
|
||||
HashMap::with_hasher(S::default()),
|
||||
@ -805,9 +809,9 @@ map_impl!(
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for net::IpAddr {
|
||||
impl<'de> Deserialize<'de> for net::IpAddr {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let s = try!(String::deserialize(deserializer));
|
||||
match s.parse() {
|
||||
@ -818,9 +822,9 @@ impl Deserialize for net::IpAddr {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for net::Ipv4Addr {
|
||||
impl<'de> Deserialize<'de> for net::Ipv4Addr {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let s = try!(String::deserialize(deserializer));
|
||||
match s.parse() {
|
||||
@ -831,9 +835,9 @@ impl Deserialize for net::Ipv4Addr {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for net::Ipv6Addr {
|
||||
impl<'de> Deserialize<'de> for net::Ipv6Addr {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let s = try!(String::deserialize(deserializer));
|
||||
match s.parse() {
|
||||
@ -846,9 +850,9 @@ impl Deserialize for net::Ipv6Addr {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for net::SocketAddr {
|
||||
impl<'de> Deserialize<'de> for net::SocketAddr {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let s = try!(String::deserialize(deserializer));
|
||||
match s.parse() {
|
||||
@ -859,9 +863,9 @@ impl Deserialize for net::SocketAddr {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for net::SocketAddrV4 {
|
||||
impl<'de> Deserialize<'de> for net::SocketAddrV4 {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let s = try!(String::deserialize(deserializer));
|
||||
match s.parse() {
|
||||
@ -872,9 +876,9 @@ impl Deserialize for net::SocketAddrV4 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for net::SocketAddrV6 {
|
||||
impl<'de> Deserialize<'de> for net::SocketAddrV6 {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let s = try!(String::deserialize(deserializer));
|
||||
match s.parse() {
|
||||
@ -890,7 +894,7 @@ impl Deserialize for net::SocketAddrV6 {
|
||||
struct PathBufVisitor;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Visitor for PathBufVisitor {
|
||||
impl<'de> Visitor<'de> for PathBufVisitor {
|
||||
type Value = path::PathBuf;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -912,9 +916,9 @@ impl Visitor for PathBufVisitor {
|
||||
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for path::PathBuf {
|
||||
impl<'de> Deserialize<'de> for path::PathBuf {
|
||||
fn deserialize<D>(deserializer: D) -> Result<path::PathBuf, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_string(PathBufVisitor)
|
||||
}
|
||||
@ -932,13 +936,13 @@ enum OsStringKind {
|
||||
static OSSTR_VARIANTS: &'static [&'static str] = &["Unix", "Windows"];
|
||||
|
||||
#[cfg(all(feature = "std", any(unix, windows)))]
|
||||
impl Deserialize for OsStringKind {
|
||||
impl<'de> Deserialize<'de> for OsStringKind {
|
||||
fn deserialize<D>(deserializer: D) -> Result<OsStringKind, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
struct KindVisitor;
|
||||
|
||||
impl Visitor for KindVisitor {
|
||||
impl<'de> Visitor<'de> for KindVisitor {
|
||||
type Value = OsStringKind;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -991,7 +995,7 @@ impl Deserialize for OsStringKind {
|
||||
struct OsStringVisitor;
|
||||
|
||||
#[cfg(all(feature = "std", any(unix, windows)))]
|
||||
impl Visitor for OsStringVisitor {
|
||||
impl<'de> Visitor<'de> for OsStringVisitor {
|
||||
type Value = OsString;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -1000,7 +1004,7 @@ impl Visitor for OsStringVisitor {
|
||||
|
||||
#[cfg(unix)]
|
||||
fn visit_enum<V>(self, visitor: V) -> Result<OsString, V::Error>
|
||||
where V: EnumVisitor,
|
||||
where V: EnumVisitor<'de>,
|
||||
{
|
||||
use std::os::unix::ffi::OsStringExt;
|
||||
|
||||
@ -1016,9 +1020,9 @@ impl Visitor for OsStringVisitor {
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", any(unix, windows)))]
|
||||
impl Deserialize for OsString {
|
||||
impl<'de> Deserialize<'de> for OsString {
|
||||
fn deserialize<D>(deserializer: D) -> Result<OsString, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_enum("OsString", OSSTR_VARIANTS, OsStringVisitor)
|
||||
}
|
||||
@ -1027,9 +1031,9 @@ impl Deserialize for OsString {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<T: Deserialize> Deserialize for Box<T> {
|
||||
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Box<T> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Box<T>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let val = try!(Deserialize::deserialize(deserializer));
|
||||
Ok(Box::new(val))
|
||||
@ -1037,9 +1041,9 @@ impl<T: Deserialize> Deserialize for Box<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<T: Deserialize> Deserialize for Box<[T]> {
|
||||
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Box<[T]> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Box<[T]>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let v: Vec<T> = try!(Deserialize::deserialize(deserializer));
|
||||
Ok(v.into_boxed_slice())
|
||||
@ -1047,9 +1051,9 @@ impl<T: Deserialize> Deserialize for Box<[T]> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl Deserialize for Box<str> {
|
||||
impl<'de> Deserialize<'de> for Box<str> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let s = try!(String::deserialize(deserializer));
|
||||
Ok(s.into_boxed_str())
|
||||
@ -1057,9 +1061,9 @@ impl Deserialize for Box<str> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<T: Deserialize> Deserialize for Arc<T> {
|
||||
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Arc<T>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let val = try!(Deserialize::deserialize(deserializer));
|
||||
Ok(Arc::new(val))
|
||||
@ -1067,9 +1071,9 @@ impl<T: Deserialize> Deserialize for Arc<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<T: Deserialize> Deserialize for Rc<T> {
|
||||
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Rc<T> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Rc<T>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let val = try!(Deserialize::deserialize(deserializer));
|
||||
Ok(Rc::new(val))
|
||||
@ -1077,13 +1081,13 @@ impl<T: Deserialize> Deserialize for Rc<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<'a, T: ?Sized> Deserialize for Cow<'a, T>
|
||||
impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T>
|
||||
where T: ToOwned,
|
||||
T::Owned: Deserialize
|
||||
T::Owned: Deserialize<'de>
|
||||
{
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<Cow<'a, T>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let val = try!(Deserialize::deserialize(deserializer));
|
||||
Ok(Cow::Owned(val))
|
||||
@ -1101,22 +1105,22 @@ impl<'a, T: ?Sized> Deserialize for Cow<'a, T>
|
||||
// nanos: u32,
|
||||
// }
|
||||
#[cfg(feature = "std")]
|
||||
impl Deserialize for Duration {
|
||||
impl<'de> Deserialize<'de> for Duration {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
enum Field {
|
||||
Secs,
|
||||
Nanos,
|
||||
};
|
||||
|
||||
impl Deserialize for Field {
|
||||
impl<'de> Deserialize<'de> for Field {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Field, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
struct FieldVisitor;
|
||||
|
||||
impl Visitor for FieldVisitor {
|
||||
impl<'de> Visitor<'de> for FieldVisitor {
|
||||
type Value = Field;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -1153,7 +1157,7 @@ impl Deserialize for Duration {
|
||||
|
||||
struct DurationVisitor;
|
||||
|
||||
impl Visitor for DurationVisitor {
|
||||
impl<'de> Visitor<'de> for DurationVisitor {
|
||||
type Value = Duration;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -1161,7 +1165,7 @@ impl Deserialize for Duration {
|
||||
}
|
||||
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<Duration, V::Error>
|
||||
where V: SeqVisitor
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
let secs: u64 = match try!(visitor.visit()) {
|
||||
Some(value) => value,
|
||||
@ -1179,7 +1183,7 @@ impl Deserialize for Duration {
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Duration, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapVisitor<'de>
|
||||
{
|
||||
let mut secs: Option<u64> = None;
|
||||
let mut nanos: Option<u32> = None;
|
||||
@ -1227,22 +1231,22 @@ impl Deserialize for Duration {
|
||||
// end: u32,
|
||||
// }
|
||||
#[cfg(feature = "std")]
|
||||
impl<Idx: Deserialize> Deserialize for std::ops::Range<Idx> {
|
||||
impl<'de, Idx: Deserialize<'de>> Deserialize<'de> for std::ops::Range<Idx> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
enum Field {
|
||||
Start,
|
||||
End,
|
||||
};
|
||||
|
||||
impl Deserialize for Field {
|
||||
impl<'de> Deserialize<'de> for Field {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Field, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
struct FieldVisitor;
|
||||
|
||||
impl Visitor for FieldVisitor {
|
||||
impl<'de> Visitor<'de> for FieldVisitor {
|
||||
type Value = Field;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -1281,7 +1285,7 @@ impl<Idx: Deserialize> Deserialize for std::ops::Range<Idx> {
|
||||
phantom: PhantomData<Idx>,
|
||||
}
|
||||
|
||||
impl<Idx: Deserialize> Visitor for RangeVisitor<Idx> {
|
||||
impl<'de, Idx: Deserialize<'de>> Visitor<'de> for RangeVisitor<Idx> {
|
||||
type Value = std::ops::Range<Idx>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -1289,7 +1293,7 @@ impl<Idx: Deserialize> Deserialize for std::ops::Range<Idx> {
|
||||
}
|
||||
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<std::ops::Range<Idx>, V::Error>
|
||||
where V: SeqVisitor
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
let start: Idx = match try!(visitor.visit()) {
|
||||
Some(value) => value,
|
||||
@ -1307,7 +1311,7 @@ impl<Idx: Deserialize> Deserialize for std::ops::Range<Idx> {
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<std::ops::Range<Idx>, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapVisitor<'de>
|
||||
{
|
||||
let mut start: Option<Idx> = None;
|
||||
let mut end: Option<Idx> = None;
|
||||
@ -1351,11 +1355,11 @@ impl<Idx: Deserialize> Deserialize for std::ops::Range<Idx> {
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[allow(deprecated)] // num::Zero is deprecated but there is no replacement
|
||||
impl<T> Deserialize for NonZero<T>
|
||||
where T: Deserialize + PartialEq + Zeroable + Zero
|
||||
impl<'de, T> Deserialize<'de> for NonZero<T>
|
||||
where T: Deserialize<'de> + PartialEq + Zeroable + Zero
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<NonZero<T>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let value = try!(Deserialize::deserialize(deserializer));
|
||||
if value == Zero::zero() {
|
||||
@ -1368,26 +1372,26 @@ impl<T> Deserialize for NonZero<T>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
impl<T, E> Deserialize for Result<T, E>
|
||||
where T: Deserialize,
|
||||
E: Deserialize
|
||||
impl<'de, T, E> Deserialize<'de> for Result<T, E>
|
||||
where T: Deserialize<'de>,
|
||||
E: Deserialize<'de>
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<Result<T, E>, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
enum Field {
|
||||
Ok,
|
||||
Err,
|
||||
}
|
||||
|
||||
impl Deserialize for Field {
|
||||
impl<'de> Deserialize<'de> for Field {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<Field, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
struct FieldVisitor;
|
||||
|
||||
impl Visitor for FieldVisitor {
|
||||
impl<'de> Visitor<'de> for FieldVisitor {
|
||||
type Value = Field;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -1440,9 +1444,9 @@ impl<T, E> Deserialize for Result<T, E>
|
||||
|
||||
struct ResultVisitor<T, E>(PhantomData<Result<T, E>>);
|
||||
|
||||
impl<T, E> Visitor for ResultVisitor<T, E>
|
||||
where T: Deserialize,
|
||||
E: Deserialize
|
||||
impl<'de, T, E> Visitor<'de> for ResultVisitor<T, E>
|
||||
where T: Deserialize<'de>,
|
||||
E: Deserialize<'de>
|
||||
{
|
||||
type Value = Result<T, E>;
|
||||
|
||||
@ -1451,7 +1455,7 @@ impl<T, E> Deserialize for Result<T, E>
|
||||
}
|
||||
|
||||
fn visit_enum<V>(self, visitor: V) -> Result<Result<T, E>, V::Error>
|
||||
where V: EnumVisitor
|
||||
where V: EnumVisitor<'de>
|
||||
{
|
||||
match try!(visitor.visit_variant()) {
|
||||
(Field::Ok, variant) => variant.visit_newtype().map(Ok),
|
||||
@ -1472,14 +1476,14 @@ impl<T, E> Deserialize for Result<T, E>
|
||||
/// Deserialize and silently eats data given to it.
|
||||
pub struct IgnoredAny;
|
||||
|
||||
impl Deserialize for IgnoredAny {
|
||||
impl<'de> Deserialize<'de> for IgnoredAny {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<IgnoredAny, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
struct IgnoredAnyVisitor;
|
||||
|
||||
impl Visitor for IgnoredAnyVisitor {
|
||||
impl<'de> Visitor<'de> for IgnoredAnyVisitor {
|
||||
type Value = IgnoredAny;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -1520,14 +1524,14 @@ impl Deserialize for IgnoredAny {
|
||||
|
||||
#[inline]
|
||||
fn visit_some<D>(self, _: D) -> Result<IgnoredAny, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
Ok(IgnoredAny)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_newtype_struct<D>(self, _: D) -> Result<IgnoredAny, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
Ok(IgnoredAny)
|
||||
}
|
||||
@ -1539,7 +1543,7 @@ impl Deserialize for IgnoredAny {
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<IgnoredAny, V::Error>
|
||||
where V: SeqVisitor
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
while let Some(_) = try!(visitor.visit::<IgnoredAny>()) {
|
||||
// Gobble
|
||||
@ -1549,7 +1553,7 @@ impl Deserialize for IgnoredAny {
|
||||
|
||||
#[inline]
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<IgnoredAny, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapVisitor<'de>
|
||||
{
|
||||
while let Some((_, _)) = try!(visitor.visit::<IgnoredAny, IgnoredAny>()) {
|
||||
// Gobble
|
||||
|
@ -147,9 +147,9 @@ pub trait Error: Sized + error::Error {
|
||||
/// # type Err = String;
|
||||
/// # fn from_str(_: &str) -> Result<Self, String> { unimplemented!() }
|
||||
/// # }
|
||||
/// impl Deserialize for IpAddr {
|
||||
/// impl<'de> Deserialize<'de> for IpAddr {
|
||||
/// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
/// where D: Deserializer
|
||||
/// where D: Deserializer<'de>
|
||||
/// {
|
||||
/// let s = try!(String::deserialize(deserializer));
|
||||
/// s.parse().map_err(Error::custom)
|
||||
@ -256,7 +256,7 @@ pub trait Error: Sized + error::Error {
|
||||
/// # use std::fmt;
|
||||
/// # #[allow(dead_code)]
|
||||
/// # struct Example;
|
||||
/// # impl Visitor for Example {
|
||||
/// # impl<'de> Visitor<'de> for Example {
|
||||
/// # type Value = ();
|
||||
/// fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E>
|
||||
/// where E: Error
|
||||
@ -376,7 +376,7 @@ impl<'a> fmt::Display for Unexpected<'a> {
|
||||
/// # use std::fmt;
|
||||
/// # #[allow(dead_code)]
|
||||
/// # struct Example;
|
||||
/// # impl Visitor for Example {
|
||||
/// # impl<'de> Visitor<'de> for Example {
|
||||
/// # type Value = ();
|
||||
/// fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E>
|
||||
/// where E: Error
|
||||
@ -405,8 +405,8 @@ pub trait Expected {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result;
|
||||
}
|
||||
|
||||
impl<T> Expected for T
|
||||
where T: Visitor
|
||||
impl<'de, T> Expected for T
|
||||
where T: Visitor<'de>
|
||||
{
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.expecting(formatter)
|
||||
@ -451,16 +451,36 @@ impl<'a> Display for Expected + 'a {
|
||||
/// [de]: https://docs.serde.rs/serde/de/index.html
|
||||
/// [codegen]: https://serde.rs/codegen.html
|
||||
/// [impl-deserialize]: https://serde.rs/impl-deserialize.html
|
||||
pub trait Deserialize: Sized {
|
||||
pub trait Deserialize<'de>: Sized {
|
||||
/// Deserialize this value from the given Serde deserializer.
|
||||
///
|
||||
/// See the [Implementing `Deserialize`][impl-deserialize] section of the
|
||||
/// manual for more information about how to implement this method.
|
||||
///
|
||||
/// [impl-deserialize]: https://serde.rs/impl-deserialize.html
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer;
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer<'de>;
|
||||
}
|
||||
|
||||
/// A data structure that can be deserialized without borrowing any data from
|
||||
/// the deserializer.
|
||||
///
|
||||
/// This is primarily useful for trait bounds on functions. For example a
|
||||
/// `from_str` function may be able to deserialize a data structure that borrows
|
||||
/// from the input string, but a `from_reader` function may only deserialize
|
||||
/// owned data.
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// pub fn from_str<'a, T>(s: &'a str) -> Result<T>
|
||||
/// where T: Deserialize<'a>;
|
||||
///
|
||||
/// pub fn from_reader<R, T>(rdr: R) -> Result<T>
|
||||
/// where R: Read,
|
||||
/// T: DeserializeOwned;
|
||||
/// ```
|
||||
pub trait DeserializeOwned: for<'de> Deserialize<'de> {}
|
||||
impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
||||
|
||||
/// `DeserializeSeed` is the stateful form of the `Deserialize` trait. If you
|
||||
/// ever find yourself looking for a way to pass data into a `Deserialize` impl,
|
||||
/// this trait is the way to do it.
|
||||
@ -479,7 +499,7 @@ pub trait Deserialize: Sized {
|
||||
/// # #[allow(dead_code)]
|
||||
/// # enum Error {}
|
||||
/// # #[allow(dead_code)]
|
||||
/// fn func<T: Deserialize>() -> Result<T, Error>
|
||||
/// fn func<'de, T: Deserialize<'de>>() -> Result<T, Error>
|
||||
/// # { unimplemented!() }
|
||||
/// ```
|
||||
///
|
||||
@ -491,7 +511,7 @@ pub trait Deserialize: Sized {
|
||||
/// # #[allow(dead_code)]
|
||||
/// # enum Error {}
|
||||
/// # #[allow(dead_code)]
|
||||
/// fn func_seed<T: DeserializeSeed>(seed: T) -> Result<T::Value, Error>
|
||||
/// fn func_seed<'de, T: DeserializeSeed<'de>>(seed: T) -> Result<T::Value, Error>
|
||||
/// # {
|
||||
/// # let _ = seed;
|
||||
/// # unimplemented!()
|
||||
@ -523,8 +543,8 @@ pub trait Deserialize: Sized {
|
||||
/// // appending each integer into the existing Vec.
|
||||
/// struct ExtendVec<'a, T: 'a>(&'a mut Vec<T>);
|
||||
///
|
||||
/// impl<'a, T> DeserializeSeed for ExtendVec<'a, T>
|
||||
/// where T: Deserialize
|
||||
/// impl<'de, 'a, T> DeserializeSeed<'de> for ExtendVec<'a, T>
|
||||
/// where T: Deserialize<'de>
|
||||
/// {
|
||||
/// // The return type of the `deserialize` method. This implementation
|
||||
/// // appends onto an existing vector but does not create any new data
|
||||
@ -532,19 +552,19 @@ pub trait Deserialize: Sized {
|
||||
/// type Value = ();
|
||||
///
|
||||
/// fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
/// where D: Deserializer
|
||||
/// where D: Deserializer<'de>
|
||||
/// {
|
||||
/// // Visitor implementation that will walk an inner array of the JSON
|
||||
/// // input.
|
||||
/// struct ExtendVecVisitor<'a, T: 'a>(&'a mut Vec<T>);
|
||||
///
|
||||
/// impl<'a, T> Visitor for ExtendVecVisitor<'a, T>
|
||||
/// where T: Deserialize
|
||||
/// impl<'de, 'a, T> Visitor<'de> for ExtendVecVisitor<'a, T>
|
||||
/// where T: Deserialize<'de>
|
||||
/// {
|
||||
/// type Value = ();
|
||||
///
|
||||
/// fn visit_seq<V>(self, mut visitor: V) -> Result<(), V::Error>
|
||||
/// where V: SeqVisitor
|
||||
/// where V: SeqVisitor<'de>
|
||||
/// {
|
||||
/// // Visit each element in the inner array and push it onto
|
||||
/// // the existing vector.
|
||||
@ -566,15 +586,15 @@ pub trait Deserialize: Sized {
|
||||
/// // Visitor implementation that will walk the outer array of the JSON input.
|
||||
/// struct FlattenedVecVisitor<T>(PhantomData<T>);
|
||||
///
|
||||
/// impl<T> Visitor for FlattenedVecVisitor<T>
|
||||
/// where T: Deserialize
|
||||
/// impl<'de, T> Visitor<'de> for FlattenedVecVisitor<T>
|
||||
/// where T: Deserialize<'de>
|
||||
/// {
|
||||
/// // This Visitor constructs a single Vec<T> to hold the flattened
|
||||
/// // contents of the inner arrays.
|
||||
/// type Value = Vec<T>;
|
||||
///
|
||||
/// fn visit_seq<V>(self, mut visitor: V) -> Result<Vec<T>, V::Error>
|
||||
/// where V: SeqVisitor
|
||||
/// where V: SeqVisitor<'de>
|
||||
/// {
|
||||
/// // Create a single Vec to hold the flattened contents.
|
||||
/// let mut vec = Vec::new();
|
||||
@ -594,29 +614,30 @@ pub trait Deserialize: Sized {
|
||||
/// }
|
||||
///
|
||||
/// # #[allow(dead_code)]
|
||||
/// # fn example<D: Deserializer>(deserializer: D) -> Result<(), D::Error> {
|
||||
/// # fn example<'de, D: Deserializer<'de>>(deserializer: D) -> Result<(), D::Error> {
|
||||
/// let visitor = FlattenedVecVisitor(PhantomData);
|
||||
/// let flattened: Vec<u64> = deserializer.deserialize_seq(visitor)?;
|
||||
/// # let _ = flattened;
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
pub trait DeserializeSeed: Sized {
|
||||
pub trait DeserializeSeed<'de>: Sized {
|
||||
/// The type produced by using this seed.
|
||||
type Value;
|
||||
|
||||
/// Equivalent to the more common `Deserialize::deserialize` method, except
|
||||
/// with some initial piece of data (the seed) passed in.
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error> where D: Deserializer;
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer<'de>;
|
||||
}
|
||||
|
||||
impl<T> DeserializeSeed for PhantomData<T>
|
||||
where T: Deserialize
|
||||
impl<'de, T> DeserializeSeed<'de> for PhantomData<T>
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
type Value = T;
|
||||
|
||||
#[inline]
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<T, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
T::deserialize(deserializer)
|
||||
}
|
||||
@ -705,7 +726,7 @@ impl<T> DeserializeSeed for PhantomData<T>
|
||||
/// what type is in the input. Know that relying on `Deserializer::deserialize`
|
||||
/// means your data type will be able to deserialize from self-describing
|
||||
/// formats only, ruling out Bincode and many others.
|
||||
pub trait Deserializer: Sized {
|
||||
pub trait Deserializer<'de>: Sized {
|
||||
/// The error type that can be returned if some error occurs during
|
||||
/// deserialization.
|
||||
type Error: Error;
|
||||
@ -719,43 +740,43 @@ pub trait Deserializer: Sized {
|
||||
/// `Deserializer::deserialize` means your data type will be able to
|
||||
/// deserialize from self-describing formats only, ruling out Bincode and
|
||||
/// many others.
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a `bool` value.
|
||||
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a `u8` value.
|
||||
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a `u16` value.
|
||||
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a `u32` value.
|
||||
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a `u64` value.
|
||||
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting an `i8` value.
|
||||
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting an `i16` value.
|
||||
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting an `i32` value.
|
||||
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting an `i64` value.
|
||||
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a `f32` value.
|
||||
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a `f64` value.
|
||||
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a `char` value.
|
||||
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a string value and does
|
||||
/// not benefit from taking ownership of buffered data owned by the
|
||||
@ -764,7 +785,7 @@ pub trait Deserializer: Sized {
|
||||
/// If the `Visitor` would benefit from taking ownership of `String` data,
|
||||
/// indiciate this to the `Deserializer` by using `deserialize_string`
|
||||
/// instead.
|
||||
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a string value and would
|
||||
/// benefit from taking ownership of buffered data owned by the
|
||||
@ -773,7 +794,7 @@ pub trait Deserializer: Sized {
|
||||
/// If the `Visitor` would not benefit from taking ownership of `String`
|
||||
/// data, indicate that to the `Deserializer` by using `deserialize_str`
|
||||
/// instead.
|
||||
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a byte array and does not
|
||||
/// benefit from taking ownership of buffered data owned by the
|
||||
@ -782,7 +803,7 @@ pub trait Deserializer: Sized {
|
||||
/// If the `Visitor` would benefit from taking ownership of `Vec<u8>` data,
|
||||
/// indicate this to the `Deserializer` by using `deserialize_byte_buf`
|
||||
/// instead.
|
||||
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a byte array and would
|
||||
/// benefit from taking ownership of buffered data owned by the
|
||||
@ -791,17 +812,17 @@ pub trait Deserializer: Sized {
|
||||
/// If the `Visitor` would not benefit from taking ownership of `Vec<u8>`
|
||||
/// data, indicate that to the `Deserializer` by using `deserialize_bytes`
|
||||
/// instead.
|
||||
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting an optional value.
|
||||
///
|
||||
/// This allows deserializers that encode an optional value as a nullable
|
||||
/// value to convert the null value into `None` and a regular value into
|
||||
/// `Some(value)`.
|
||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a unit value.
|
||||
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a unit struct with a
|
||||
/// particular name.
|
||||
@ -809,7 +830,7 @@ pub trait Deserializer: Sized {
|
||||
name: &'static str,
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a newtype struct with a
|
||||
/// particular name.
|
||||
@ -817,10 +838,10 @@ pub trait Deserializer: Sized {
|
||||
name: &'static str,
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a sequence of values.
|
||||
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a sequence of values and
|
||||
/// knows how many values there are without looking at the serialized data.
|
||||
@ -828,12 +849,12 @@ pub trait Deserializer: Sized {
|
||||
len: usize,
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a tuple value with a
|
||||
/// particular number of elements.
|
||||
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a tuple struct with a
|
||||
/// particular name and number of fields.
|
||||
@ -842,10 +863,10 @@ pub trait Deserializer: Sized {
|
||||
len: usize,
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a map of key-value pairs.
|
||||
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor;
|
||||
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error> where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting a struct with a particular
|
||||
/// name and fields.
|
||||
@ -854,12 +875,12 @@ pub trait Deserializer: Sized {
|
||||
fields: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting the name of a struct
|
||||
/// field.
|
||||
fn deserialize_struct_field<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type is expecting an enum value with a
|
||||
/// particular name and possible variants.
|
||||
@ -868,14 +889,14 @@ pub trait Deserializer: Sized {
|
||||
variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Hint that the `Deserialize` type needs to deserialize a value whose type
|
||||
/// doesn't matter because it is ignored.
|
||||
///
|
||||
/// Deserializers for non-self-describing formats may not support this mode.
|
||||
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -892,7 +913,7 @@ pub trait Deserializer: Sized {
|
||||
/// min: usize,
|
||||
/// }
|
||||
///
|
||||
/// impl Visitor for LongString {
|
||||
/// impl<'de> Visitor<'de> for LongString {
|
||||
/// type Value = String;
|
||||
///
|
||||
/// fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
@ -910,7 +931,7 @@ pub trait Deserializer: Sized {
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub trait Visitor: Sized {
|
||||
pub trait Visitor<'de>: Sized {
|
||||
/// The value produced by this visitor.
|
||||
type Value;
|
||||
|
||||
@ -925,7 +946,7 @@ pub trait Visitor: Sized {
|
||||
/// # use std::fmt;
|
||||
/// # #[allow(dead_code)]
|
||||
/// # struct S { max: usize }
|
||||
/// # impl serde::de::Visitor for S {
|
||||
/// # impl<'de> serde::de::Visitor<'de> for S {
|
||||
/// # type Value = ();
|
||||
/// fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
/// write!(formatter, "an integer between 0 and {}", self.max)
|
||||
@ -1035,6 +1056,21 @@ pub trait Visitor: Sized {
|
||||
Err(Error::invalid_type(Unexpected::Str(v), &self))
|
||||
}
|
||||
|
||||
/// Deserialize a `&str` that is borrowed from the input data.
|
||||
///
|
||||
/// This enables zero-copy deserialization of strings in some formats. For
|
||||
/// example JSON input containing the JSON string `"borrowed"` can be
|
||||
/// deserialized with zero copying into a `&'a str` as long as the input
|
||||
/// data outlives `'a`.
|
||||
///
|
||||
/// The default implementation forwards to `visit_str`.
|
||||
#[inline]
|
||||
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
|
||||
where E: Error
|
||||
{
|
||||
self.visit_str(v)
|
||||
}
|
||||
|
||||
/// Deserialize a `String` into a `Value`.
|
||||
///
|
||||
/// This method allows the `Visitor` to avoid a copy by taking ownership of
|
||||
@ -1073,7 +1109,7 @@ pub trait Visitor: Sized {
|
||||
|
||||
/// Deserialize a present optional `Value`.
|
||||
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let _ = deserializer;
|
||||
Err(Error::invalid_type(Unexpected::Option, &self))
|
||||
@ -1081,7 +1117,7 @@ pub trait Visitor: Sized {
|
||||
|
||||
/// Deserialize `Value` as a newtype struct.
|
||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where D: Deserializer
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
let _ = deserializer;
|
||||
Err(Error::invalid_type(Unexpected::NewtypeStruct, &self))
|
||||
@ -1089,7 +1125,7 @@ pub trait Visitor: Sized {
|
||||
|
||||
/// Deserialize `Value` as a sequence of elements.
|
||||
fn visit_seq<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: SeqVisitor
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
let _ = visitor;
|
||||
Err(Error::invalid_type(Unexpected::Seq, &self))
|
||||
@ -1097,7 +1133,7 @@ pub trait Visitor: Sized {
|
||||
|
||||
/// Deserialize `Value` as a key-value map.
|
||||
fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: MapVisitor
|
||||
where V: MapVisitor<'de>
|
||||
{
|
||||
let _ = visitor;
|
||||
Err(Error::invalid_type(Unexpected::Map, &self))
|
||||
@ -1105,7 +1141,7 @@ pub trait Visitor: Sized {
|
||||
|
||||
/// Deserialize `Value` as an enum.
|
||||
fn visit_enum<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||
where V: EnumVisitor
|
||||
where V: EnumVisitor<'de>
|
||||
{
|
||||
let _ = visitor;
|
||||
Err(Error::invalid_type(Unexpected::Enum, &self))
|
||||
@ -1128,6 +1164,20 @@ pub trait Visitor: Sized {
|
||||
Err(Error::invalid_type(Unexpected::Bytes(v), &self))
|
||||
}
|
||||
|
||||
/// Deserialize a `&[u8]` that is borrowed from the input data.
|
||||
///
|
||||
/// This enables zero-copy deserialization of bytes in some formats. For
|
||||
/// example Bincode data containing bytes can be deserialized with zero
|
||||
/// copying into a `&'a [u8]` as long as the input data outlives `'a`.
|
||||
///
|
||||
/// The default implementation forwards to `visit_bytes`.
|
||||
#[inline]
|
||||
fn visit_borrowed_bytes<E>(self, v: &'de [u8]) -> Result<Self::Value, E>
|
||||
where E: Error
|
||||
{
|
||||
self.visit_bytes(v)
|
||||
}
|
||||
|
||||
/// Deserialize a `Vec<u8>` into a `Value`.
|
||||
///
|
||||
/// This method allows the `Visitor` to avoid a copy by taking ownership of
|
||||
@ -1157,7 +1207,7 @@ pub trait Visitor: Sized {
|
||||
///
|
||||
/// This is a trait that a `Deserializer` passes to a `Visitor` implementation,
|
||||
/// which deserializes each item in a sequence.
|
||||
pub trait SeqVisitor {
|
||||
pub trait SeqVisitor<'de> {
|
||||
/// The error type that can be returned if some error occurs during
|
||||
/// deserialization.
|
||||
type Error: Error;
|
||||
@ -1168,7 +1218,7 @@ pub trait SeqVisitor {
|
||||
/// `Deserialize` implementations should typically use `SeqVisitor::visit`
|
||||
/// instead.
|
||||
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where T: DeserializeSeed;
|
||||
where T: DeserializeSeed<'de>;
|
||||
|
||||
/// This returns `Ok(Some(value))` for the next value in the sequence, or
|
||||
/// `Ok(None)` if there are no more remaining items.
|
||||
@ -1177,7 +1227,7 @@ pub trait SeqVisitor {
|
||||
/// `SeqVisitor` implementations should not override the default behavior.
|
||||
#[inline]
|
||||
fn visit<T>(&mut self) -> Result<Option<T>, Self::Error>
|
||||
where T: Deserialize
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
self.visit_seed(PhantomData)
|
||||
}
|
||||
@ -1189,21 +1239,21 @@ pub trait SeqVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, V> SeqVisitor for &'a mut V
|
||||
where V: SeqVisitor
|
||||
impl<'de, 'a, V> SeqVisitor<'de> for &'a mut V
|
||||
where V: SeqVisitor<'de>
|
||||
{
|
||||
type Error = V::Error;
|
||||
|
||||
#[inline]
|
||||
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, V::Error>
|
||||
where T: DeserializeSeed
|
||||
where T: DeserializeSeed<'de>
|
||||
{
|
||||
(**self).visit_seed(seed)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit<T>(&mut self) -> Result<Option<T>, V::Error>
|
||||
where T: Deserialize
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
(**self).visit()
|
||||
}
|
||||
@ -1219,7 +1269,7 @@ impl<'a, V> SeqVisitor for &'a mut V
|
||||
/// `MapVisitor` visits each item in a sequence.
|
||||
///
|
||||
/// This is a trait that a `Deserializer` passes to a `Visitor` implementation.
|
||||
pub trait MapVisitor {
|
||||
pub trait MapVisitor<'de> {
|
||||
/// The error type that can be returned if some error occurs during
|
||||
/// deserialization.
|
||||
type Error: Error;
|
||||
@ -1230,14 +1280,14 @@ pub trait MapVisitor {
|
||||
/// `Deserialize` implementations should typically use
|
||||
/// `MapVisitor::visit_key` or `MapVisitor::visit` instead.
|
||||
fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error>
|
||||
where K: DeserializeSeed;
|
||||
where K: DeserializeSeed<'de>;
|
||||
|
||||
/// This returns a `Ok(value)` for the next value in the map.
|
||||
///
|
||||
/// `Deserialize` implementations should typically use
|
||||
/// `MapVisitor::visit_value` instead.
|
||||
fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error>
|
||||
where V: DeserializeSeed;
|
||||
where V: DeserializeSeed<'de>;
|
||||
|
||||
/// This returns `Ok(Some((key, value)))` for the next (key-value) pair in
|
||||
/// the map, or `Ok(None)` if there are no more remaining items.
|
||||
@ -1252,8 +1302,8 @@ pub trait MapVisitor {
|
||||
kseed: K,
|
||||
vseed: V)
|
||||
-> Result<Option<(K::Value, V::Value)>, Self::Error>
|
||||
where K: DeserializeSeed,
|
||||
V: DeserializeSeed
|
||||
where K: DeserializeSeed<'de>,
|
||||
V: DeserializeSeed<'de>
|
||||
{
|
||||
match try!(self.visit_key_seed(kseed)) {
|
||||
Some(key) => {
|
||||
@ -1271,7 +1321,7 @@ pub trait MapVisitor {
|
||||
/// `MapVisitor` implementations should not override the default behavior.
|
||||
#[inline]
|
||||
fn visit_key<K>(&mut self) -> Result<Option<K>, Self::Error>
|
||||
where K: Deserialize
|
||||
where K: Deserialize<'de>
|
||||
{
|
||||
self.visit_key_seed(PhantomData)
|
||||
}
|
||||
@ -1282,7 +1332,7 @@ pub trait MapVisitor {
|
||||
/// `MapVisitor` implementations should not override the default behavior.
|
||||
#[inline]
|
||||
fn visit_value<V>(&mut self) -> Result<V, Self::Error>
|
||||
where V: Deserialize
|
||||
where V: Deserialize<'de>
|
||||
{
|
||||
self.visit_value_seed(PhantomData)
|
||||
}
|
||||
@ -1294,8 +1344,8 @@ pub trait MapVisitor {
|
||||
/// `MapVisitor` implementations should not override the default behavior.
|
||||
#[inline]
|
||||
fn visit<K, V>(&mut self) -> Result<Option<(K, V)>, Self::Error>
|
||||
where K: Deserialize,
|
||||
V: Deserialize
|
||||
where K: Deserialize<'de>,
|
||||
V: Deserialize<'de>
|
||||
{
|
||||
self.visit_seed(PhantomData, PhantomData)
|
||||
}
|
||||
@ -1307,21 +1357,21 @@ pub trait MapVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, V_> MapVisitor for &'a mut V_
|
||||
where V_: MapVisitor
|
||||
impl<'de, 'a, V_> MapVisitor<'de> for &'a mut V_
|
||||
where V_: MapVisitor<'de>
|
||||
{
|
||||
type Error = V_::Error;
|
||||
|
||||
#[inline]
|
||||
fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error>
|
||||
where K: DeserializeSeed
|
||||
where K: DeserializeSeed<'de>
|
||||
{
|
||||
(**self).visit_key_seed(seed)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error>
|
||||
where V: DeserializeSeed
|
||||
where V: DeserializeSeed<'de>
|
||||
{
|
||||
(**self).visit_value_seed(seed)
|
||||
}
|
||||
@ -1331,30 +1381,30 @@ impl<'a, V_> MapVisitor for &'a mut V_
|
||||
kseed: K,
|
||||
vseed: V)
|
||||
-> Result<Option<(K::Value, V::Value)>, Self::Error>
|
||||
where K: DeserializeSeed,
|
||||
V: DeserializeSeed
|
||||
where K: DeserializeSeed<'de>,
|
||||
V: DeserializeSeed<'de>
|
||||
{
|
||||
(**self).visit_seed(kseed, vseed)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit<K, V>(&mut self) -> Result<Option<(K, V)>, V_::Error>
|
||||
where K: Deserialize,
|
||||
V: Deserialize
|
||||
where K: Deserialize<'de>,
|
||||
V: Deserialize<'de>
|
||||
{
|
||||
(**self).visit()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_key<K>(&mut self) -> Result<Option<K>, V_::Error>
|
||||
where K: Deserialize
|
||||
where K: Deserialize<'de>
|
||||
{
|
||||
(**self).visit_key()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_value<V>(&mut self) -> Result<V, V_::Error>
|
||||
where V: Deserialize
|
||||
where V: Deserialize<'de>
|
||||
{
|
||||
(**self).visit_value()
|
||||
}
|
||||
@ -1370,20 +1420,20 @@ impl<'a, V_> MapVisitor for &'a mut V_
|
||||
/// `EnumVisitor` is a visitor that is created by the `Deserializer` and passed
|
||||
/// to the `Deserialize` in order to identify which variant of an enum to
|
||||
/// deserialize.
|
||||
pub trait EnumVisitor: Sized {
|
||||
pub trait EnumVisitor<'de>: Sized {
|
||||
/// The error type that can be returned if some error occurs during
|
||||
/// deserialization.
|
||||
type Error: Error;
|
||||
/// The `Visitor` that will be used to deserialize the content of the enum
|
||||
/// variant.
|
||||
type Variant: VariantVisitor<Error = Self::Error>;
|
||||
type Variant: VariantVisitor<'de, Error = Self::Error>;
|
||||
|
||||
/// `visit_variant` is called to identify which variant to deserialize.
|
||||
///
|
||||
/// `Deserialize` implementations should typically use
|
||||
/// `EnumVisitor::visit_variant` instead.
|
||||
fn visit_variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error>
|
||||
where V: DeserializeSeed;
|
||||
where V: DeserializeSeed<'de>;
|
||||
|
||||
/// `visit_variant` is called to identify which variant to deserialize.
|
||||
///
|
||||
@ -1391,7 +1441,7 @@ pub trait EnumVisitor: Sized {
|
||||
/// `EnumVisitor` implementations should not override the default behavior.
|
||||
#[inline]
|
||||
fn visit_variant<V>(self) -> Result<(V, Self::Variant), Self::Error>
|
||||
where V: Deserialize
|
||||
where V: Deserialize<'de>
|
||||
{
|
||||
self.visit_variant_seed(PhantomData)
|
||||
}
|
||||
@ -1400,7 +1450,7 @@ pub trait EnumVisitor: Sized {
|
||||
/// `VariantVisitor` is a visitor that is created by the `Deserializer` and
|
||||
/// passed to the `Deserialize` to deserialize the content of a particular enum
|
||||
/// variant.
|
||||
pub trait VariantVisitor: Sized {
|
||||
pub trait VariantVisitor<'de>: Sized {
|
||||
/// The error type that can be returned if some error occurs during
|
||||
/// deserialization. Must match the error type of our `EnumVisitor`.
|
||||
type Error: Error;
|
||||
@ -1437,7 +1487,7 @@ pub trait VariantVisitor: Sized {
|
||||
/// }
|
||||
/// ```
|
||||
fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
|
||||
where T: DeserializeSeed;
|
||||
where T: DeserializeSeed<'de>;
|
||||
|
||||
/// Called when deserializing a variant with a single value.
|
||||
///
|
||||
@ -1446,7 +1496,7 @@ pub trait VariantVisitor: Sized {
|
||||
/// behavior.
|
||||
#[inline]
|
||||
fn visit_newtype<T>(self) -> Result<T, Self::Error>
|
||||
where T: Deserialize
|
||||
where T: Deserialize<'de>
|
||||
{
|
||||
self.visit_newtype_seed(PhantomData)
|
||||
}
|
||||
@ -1470,7 +1520,7 @@ pub trait VariantVisitor: Sized {
|
||||
/// }
|
||||
/// ```
|
||||
fn visit_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
|
||||
/// Called when deserializing a struct-like variant.
|
||||
///
|
||||
@ -1494,7 +1544,7 @@ pub trait VariantVisitor: Sized {
|
||||
fields: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor;
|
||||
where V: Visitor<'de>;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -9,25 +9,25 @@ pub use de::content::{Content, ContentRefDeserializer, ContentDeserializer, Tagg
|
||||
|
||||
/// If the missing field is of type `Option<T>` then treat is as `None`,
|
||||
/// otherwise it is an error.
|
||||
pub fn missing_field<V, E>(field: &'static str) -> Result<V, E>
|
||||
where V: Deserialize,
|
||||
pub fn missing_field<'de, V, E>(field: &'static str) -> Result<V, E>
|
||||
where V: Deserialize<'de>,
|
||||
E: Error
|
||||
{
|
||||
struct MissingFieldDeserializer<E>(&'static str, PhantomData<E>);
|
||||
|
||||
impl<E> Deserializer for MissingFieldDeserializer<E>
|
||||
impl<'de, E> Deserializer<'de> for MissingFieldDeserializer<E>
|
||||
where E: Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(self, _visitor: V) -> Result<V::Value, E>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
Err(Error::missing_field(self.0))
|
||||
}
|
||||
|
||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, E>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
visitor.visit_none()
|
||||
}
|
||||
|
@ -83,9 +83,9 @@ impl error::Error for Error {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This trait converts primitive types into a deserializer.
|
||||
pub trait ValueDeserializer<E: de::Error = Error> {
|
||||
pub trait ValueDeserializer<'de, E: de::Error = Error> {
|
||||
/// The actual deserializer type.
|
||||
type Deserializer: de::Deserializer<Error = E>;
|
||||
type Deserializer: de::Deserializer<'de, Error = E>;
|
||||
|
||||
/// Convert this value into a deserializer.
|
||||
fn into_deserializer(self) -> Self::Deserializer;
|
||||
@ -93,7 +93,7 @@ pub trait ValueDeserializer<E: de::Error = Error> {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
impl<E> ValueDeserializer<E> for ()
|
||||
impl<'de, E> ValueDeserializer<'de, E> for ()
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = UnitDeserializer<E>;
|
||||
@ -108,7 +108,7 @@ pub struct UnitDeserializer<E> {
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> de::Deserializer for UnitDeserializer<E>
|
||||
impl<'de, E> de::Deserializer<'de> for UnitDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
@ -120,13 +120,13 @@ impl<E> de::Deserializer for UnitDeserializer<E>
|
||||
}
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_unit()
|
||||
}
|
||||
|
||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_none()
|
||||
}
|
||||
@ -142,7 +142,7 @@ macro_rules! primitive_deserializer {
|
||||
marker: PhantomData<E>
|
||||
}
|
||||
|
||||
impl<E> ValueDeserializer<E> for $ty
|
||||
impl<'de, E> ValueDeserializer<'de, E> for $ty
|
||||
where E: de::Error,
|
||||
{
|
||||
type Deserializer = $name<E>;
|
||||
@ -155,7 +155,7 @@ macro_rules! primitive_deserializer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::Deserializer for $name<E>
|
||||
impl<'de, E> de::Deserializer<'de> for $name<E>
|
||||
where E: de::Error,
|
||||
{
|
||||
type Error = E;
|
||||
@ -167,7 +167,7 @@ macro_rules! primitive_deserializer {
|
||||
}
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor,
|
||||
where V: de::Visitor<'de>,
|
||||
{
|
||||
visitor.$method(self.value $($cast)*)
|
||||
}
|
||||
@ -195,7 +195,7 @@ pub struct U32Deserializer<E> {
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> ValueDeserializer<E> for u32
|
||||
impl<'de, E> ValueDeserializer<'de, E> for u32
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = U32Deserializer<E>;
|
||||
@ -208,7 +208,7 @@ impl<E> ValueDeserializer<E> for u32
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::Deserializer for U32Deserializer<E>
|
||||
impl<'de, E> de::Deserializer<'de> for U32Deserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
@ -220,7 +220,7 @@ impl<E> de::Deserializer for U32Deserializer<E>
|
||||
}
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_u32(self.value)
|
||||
}
|
||||
@ -230,20 +230,20 @@ impl<E> de::Deserializer for U32Deserializer<E>
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_enum(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::EnumVisitor for U32Deserializer<E>
|
||||
impl<'de, E> de::EnumVisitor<'de> for U32Deserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
type Variant = private::UnitOnly<E>;
|
||||
|
||||
fn visit_variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
seed.deserialize(self).map(private::unit_only)
|
||||
}
|
||||
@ -257,7 +257,7 @@ pub struct StrDeserializer<'a, E> {
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, E> ValueDeserializer<E> for &'a str
|
||||
impl<'de, 'a, E> ValueDeserializer<'de, E> for &'a str
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = StrDeserializer<'a, E>;
|
||||
@ -270,13 +270,13 @@ impl<'a, E> ValueDeserializer<E> for &'a str
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::Deserializer for StrDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::Deserializer<'de> for StrDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_str(self.value)
|
||||
}
|
||||
@ -286,7 +286,7 @@ impl<'a, E> de::Deserializer for StrDeserializer<'a, E>
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_enum(self)
|
||||
}
|
||||
@ -298,14 +298,14 @@ impl<'a, E> de::Deserializer for StrDeserializer<'a, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::EnumVisitor for StrDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::EnumVisitor<'de> for StrDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
type Variant = private::UnitOnly<E>;
|
||||
|
||||
fn visit_variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
seed.deserialize(self).map(private::unit_only)
|
||||
}
|
||||
@ -321,7 +321,7 @@ pub struct StringDeserializer<E> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<E> ValueDeserializer<E> for String
|
||||
impl<'de, E> ValueDeserializer<'de, E> for String
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = StringDeserializer<E>;
|
||||
@ -335,13 +335,13 @@ impl<E> ValueDeserializer<E> for String
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<E> de::Deserializer for StringDeserializer<E>
|
||||
impl<'de, E> de::Deserializer<'de> for StringDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_string(self.value)
|
||||
}
|
||||
@ -351,7 +351,7 @@ impl<E> de::Deserializer for StringDeserializer<E>
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_enum(self)
|
||||
}
|
||||
@ -364,14 +364,14 @@ impl<E> de::Deserializer for StringDeserializer<E>
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<'a, E> de::EnumVisitor for StringDeserializer<E>
|
||||
impl<'de, 'a, E> de::EnumVisitor<'de> for StringDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
type Variant = private::UnitOnly<E>;
|
||||
|
||||
fn visit_variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
seed.deserialize(self).map(private::unit_only)
|
||||
}
|
||||
@ -387,7 +387,7 @@ pub struct CowStrDeserializer<'a, E> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<'a, E> ValueDeserializer<E> for Cow<'a, str>
|
||||
impl<'de, 'a, E> ValueDeserializer<'de, E> for Cow<'a, str>
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = CowStrDeserializer<'a, E>;
|
||||
@ -401,13 +401,13 @@ impl<'a, E> ValueDeserializer<E> for Cow<'a, str>
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<'a, E> de::Deserializer for CowStrDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::Deserializer<'de> for CowStrDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
match self.value {
|
||||
Cow::Borrowed(string) => visitor.visit_str(string),
|
||||
@ -420,7 +420,7 @@ impl<'a, E> de::Deserializer for CowStrDeserializer<'a, E>
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_enum(self)
|
||||
}
|
||||
@ -433,14 +433,14 @@ impl<'a, E> de::Deserializer for CowStrDeserializer<'a, E>
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<'a, E> de::EnumVisitor for CowStrDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::EnumVisitor<'de> for CowStrDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
type Variant = private::UnitOnly<E>;
|
||||
|
||||
fn visit_variant_seed<T>(self, seed: T) -> Result<(T::Value, Self::Variant), Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
seed.deserialize(self).map(private::unit_only)
|
||||
}
|
||||
@ -485,15 +485,15 @@ impl<I, E> SeqDeserializer<I, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T, E> de::Deserializer for SeqDeserializer<I, E>
|
||||
impl<'de, I, T, E> de::Deserializer<'de> for SeqDeserializer<I, E>
|
||||
where I: Iterator<Item = T>,
|
||||
T: ValueDeserializer<E>,
|
||||
T: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
let v = try!(visitor.visit_seq(&mut self));
|
||||
try!(self.end());
|
||||
@ -507,15 +507,15 @@ impl<I, T, E> de::Deserializer for SeqDeserializer<I, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T, E> de::SeqVisitor for SeqDeserializer<I, E>
|
||||
impl<'de, I, T, E> de::SeqVisitor<'de> for SeqDeserializer<I, E>
|
||||
where I: Iterator<Item = T>,
|
||||
T: ValueDeserializer<E>,
|
||||
T: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_seed<V>(&mut self, seed: V) -> Result<Option<V::Value>, Self::Error>
|
||||
where V: de::DeserializeSeed
|
||||
where V: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(value) => {
|
||||
@ -546,8 +546,8 @@ impl Expected for ExpectedInSeq {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<T, E> ValueDeserializer<E> for Vec<T>
|
||||
where T: ValueDeserializer<E>,
|
||||
impl<'de, T, E> ValueDeserializer<'de, E> for Vec<T>
|
||||
where T: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Deserializer = SeqDeserializer<vec::IntoIter<T>, E>;
|
||||
@ -558,8 +558,8 @@ impl<T, E> ValueDeserializer<E> for Vec<T>
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<T, E> ValueDeserializer<E> for BTreeSet<T>
|
||||
where T: ValueDeserializer<E> + Eq + Ord,
|
||||
impl<'de, T, E> ValueDeserializer<'de, E> for BTreeSet<T>
|
||||
where T: ValueDeserializer<'de, E> + Eq + Ord,
|
||||
E: de::Error
|
||||
{
|
||||
type Deserializer = SeqDeserializer<btree_set::IntoIter<T>, E>;
|
||||
@ -570,8 +570,8 @@ impl<T, E> ValueDeserializer<E> for BTreeSet<T>
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T, E> ValueDeserializer<E> for HashSet<T>
|
||||
where T: ValueDeserializer<E> + Eq + Hash,
|
||||
impl<'de, T, E> ValueDeserializer<'de, E> for HashSet<T>
|
||||
where T: ValueDeserializer<'de, E> + Eq + Hash,
|
||||
E: de::Error
|
||||
{
|
||||
type Deserializer = SeqDeserializer<hash_set::IntoIter<T>, E>;
|
||||
@ -584,31 +584,27 @@ impl<T, E> ValueDeserializer<E> for HashSet<T>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// A helper deserializer that deserializes a sequence using a `SeqVisitor`.
|
||||
pub struct SeqVisitorDeserializer<V_, E> {
|
||||
pub struct SeqVisitorDeserializer<V_> {
|
||||
visitor: V_,
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<V_, E> SeqVisitorDeserializer<V_, E>
|
||||
where V_: de::SeqVisitor<Error = E>,
|
||||
E: de::Error
|
||||
{
|
||||
impl<V_> SeqVisitorDeserializer<V_> {
|
||||
/// Construct a new `SeqVisitorDeserializer<V_, E>`.
|
||||
pub fn new(visitor: V_) -> Self {
|
||||
SeqVisitorDeserializer {
|
||||
visitor: visitor,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V_, E> de::Deserializer for SeqVisitorDeserializer<V_, E>
|
||||
where V_: de::SeqVisitor<Error = E>,
|
||||
E: de::Error
|
||||
impl<'de, V_> de::Deserializer<'de> for SeqVisitorDeserializer<V_>
|
||||
where V_: de::SeqVisitor<'de>
|
||||
{
|
||||
type Error = E;
|
||||
type Error = V_::Error;
|
||||
|
||||
fn deserialize<V: de::Visitor>(self, visitor: V) -> Result<V::Value, Self::Error> {
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_seq(self.visitor)
|
||||
}
|
||||
|
||||
@ -622,24 +618,25 @@ impl<V_, E> de::Deserializer for SeqVisitorDeserializer<V_, E>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// A helper deserializer that deserializes a map.
|
||||
pub struct MapDeserializer<I, E>
|
||||
pub struct MapDeserializer<'de, I, E>
|
||||
where I: Iterator,
|
||||
I::Item: private::Pair,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<'de, E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
iter: iter::Fuse<I>,
|
||||
value: Option<<I::Item as private::Pair>::Second>,
|
||||
count: usize,
|
||||
marker: PhantomData<E>,
|
||||
lifetime: PhantomData<&'de ()>,
|
||||
error: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<I, E> MapDeserializer<I, E>
|
||||
impl<'de, I, E> MapDeserializer<'de, I, E>
|
||||
where I: Iterator,
|
||||
I::Item: private::Pair,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<'de, E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
/// Construct a new `MapDeserializer<I, K, V, E>`.
|
||||
@ -648,7 +645,8 @@ impl<I, E> MapDeserializer<I, E>
|
||||
iter: iter.fuse(),
|
||||
value: None,
|
||||
count: 0,
|
||||
marker: PhantomData,
|
||||
lifetime: PhantomData,
|
||||
error: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@ -681,17 +679,17 @@ impl<I, E> MapDeserializer<I, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, E> de::Deserializer for MapDeserializer<I, E>
|
||||
impl<'de, I, E> de::Deserializer<'de> for MapDeserializer<'de, I, E>
|
||||
where I: Iterator,
|
||||
I::Item: private::Pair,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<'de, E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V_>(mut self, visitor: V_) -> Result<V_::Value, Self::Error>
|
||||
where V_: de::Visitor
|
||||
where V_: de::Visitor<'de>
|
||||
{
|
||||
let value = try!(visitor.visit_map(&mut self));
|
||||
try!(self.end());
|
||||
@ -699,7 +697,7 @@ impl<I, E> de::Deserializer for MapDeserializer<I, E>
|
||||
}
|
||||
|
||||
fn deserialize_seq<V_>(mut self, visitor: V_) -> Result<V_::Value, Self::Error>
|
||||
where V_: de::Visitor
|
||||
where V_: de::Visitor<'de>
|
||||
{
|
||||
let value = try!(visitor.visit_seq(&mut self));
|
||||
try!(self.end());
|
||||
@ -710,7 +708,7 @@ impl<I, E> de::Deserializer for MapDeserializer<I, E>
|
||||
_len: usize,
|
||||
visitor: V_)
|
||||
-> Result<V_::Value, Self::Error>
|
||||
where V_: de::Visitor
|
||||
where V_: de::Visitor<'de>
|
||||
{
|
||||
self.deserialize_seq(visitor)
|
||||
}
|
||||
@ -722,17 +720,17 @@ impl<I, E> de::Deserializer for MapDeserializer<I, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, E> de::MapVisitor for MapDeserializer<I, E>
|
||||
impl<'de, I, E> de::MapVisitor<'de> for MapDeserializer<'de, I, E>
|
||||
where I: Iterator,
|
||||
I::Item: private::Pair,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<'de, E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.next_pair() {
|
||||
Some((key, value)) => {
|
||||
@ -744,7 +742,7 @@ impl<I, E> de::MapVisitor for MapDeserializer<I, E>
|
||||
}
|
||||
|
||||
fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
let value = self.value.take();
|
||||
// Panic because this indicates a bug in the program rather than an
|
||||
@ -757,8 +755,8 @@ impl<I, E> de::MapVisitor for MapDeserializer<I, E>
|
||||
kseed: TK,
|
||||
vseed: TV)
|
||||
-> Result<Option<(TK::Value, TV::Value)>, Self::Error>
|
||||
where TK: de::DeserializeSeed,
|
||||
TV: de::DeserializeSeed
|
||||
where TK: de::DeserializeSeed<'de>,
|
||||
TV: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.next_pair() {
|
||||
Some((key, value)) => {
|
||||
@ -775,17 +773,17 @@ impl<I, E> de::MapVisitor for MapDeserializer<I, E>
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, E> de::SeqVisitor for MapDeserializer<I, E>
|
||||
impl<'de, I, E> de::SeqVisitor<'de> for MapDeserializer<'de, I, E>
|
||||
where I: Iterator,
|
||||
I::Item: private::Pair,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<E>,
|
||||
<I::Item as private::Pair>::First: ValueDeserializer<'de, E>,
|
||||
<I::Item as private::Pair>::Second: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
match self.next_pair() {
|
||||
Some((k, v)) => {
|
||||
@ -805,9 +803,9 @@ impl<I, E> de::SeqVisitor for MapDeserializer<I, E>
|
||||
// sequence of pairs.
|
||||
struct PairDeserializer<A, B, E>(A, B, PhantomData<E>);
|
||||
|
||||
impl<A, B, E> de::Deserializer for PairDeserializer<A, B, E>
|
||||
where A: ValueDeserializer<E>,
|
||||
B: ValueDeserializer<E>,
|
||||
impl<'de, A, B, E> de::Deserializer<'de> for PairDeserializer<A, B, E>
|
||||
where A: ValueDeserializer<'de, E>,
|
||||
B: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
@ -819,13 +817,13 @@ impl<A, B, E> de::Deserializer for PairDeserializer<A, B, E>
|
||||
}
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
self.deserialize_seq(visitor)
|
||||
}
|
||||
|
||||
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
let mut pair_visitor = PairVisitor(Some(self.0), Some(self.1), PhantomData);
|
||||
let pair = try!(visitor.visit_seq(&mut pair_visitor));
|
||||
@ -840,7 +838,7 @@ impl<A, B, E> de::Deserializer for PairDeserializer<A, B, E>
|
||||
}
|
||||
|
||||
fn deserialize_seq_fixed_size<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
if len == 2 {
|
||||
self.deserialize_seq(visitor)
|
||||
@ -854,15 +852,15 @@ impl<A, B, E> de::Deserializer for PairDeserializer<A, B, E>
|
||||
|
||||
struct PairVisitor<A, B, E>(Option<A>, Option<B>, PhantomData<E>);
|
||||
|
||||
impl<A, B, E> de::SeqVisitor for PairVisitor<A, B, E>
|
||||
where A: ValueDeserializer<E>,
|
||||
B: ValueDeserializer<E>,
|
||||
impl<'de, A, B, E> de::SeqVisitor<'de> for PairVisitor<A, B, E>
|
||||
where A: ValueDeserializer<'de, E>,
|
||||
B: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
if let Some(k) = self.0.take() {
|
||||
seed.deserialize(k.into_deserializer()).map(Some)
|
||||
@ -900,12 +898,12 @@ impl Expected for ExpectedInMap {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<K, V, E> ValueDeserializer<E> for BTreeMap<K, V>
|
||||
where K: ValueDeserializer<E> + Eq + Ord,
|
||||
V: ValueDeserializer<E>,
|
||||
impl<'de, K, V, E> ValueDeserializer<'de, E> for BTreeMap<K, V>
|
||||
where K: ValueDeserializer<'de, E> + Eq + Ord,
|
||||
V: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Deserializer = MapDeserializer<btree_map::IntoIter<K, V>, E>;
|
||||
type Deserializer = MapDeserializer<'de, btree_map::IntoIter<K, V>, E>;
|
||||
|
||||
fn into_deserializer(self) -> Self::Deserializer {
|
||||
MapDeserializer::new(self.into_iter())
|
||||
@ -913,12 +911,12 @@ impl<K, V, E> ValueDeserializer<E> for BTreeMap<K, V>
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<K, V, E> ValueDeserializer<E> for HashMap<K, V>
|
||||
where K: ValueDeserializer<E> + Eq + Hash,
|
||||
V: ValueDeserializer<E>,
|
||||
impl<'de, K, V, E> ValueDeserializer<'de, E> for HashMap<K, V>
|
||||
where K: ValueDeserializer<'de, E> + Eq + Hash,
|
||||
V: ValueDeserializer<'de, E>,
|
||||
E: de::Error
|
||||
{
|
||||
type Deserializer = MapDeserializer<hash_map::IntoIter<K, V>, E>;
|
||||
type Deserializer = MapDeserializer<'de, hash_map::IntoIter<K, V>, E>;
|
||||
|
||||
fn into_deserializer(self) -> Self::Deserializer {
|
||||
MapDeserializer::new(self.into_iter())
|
||||
@ -928,31 +926,27 @@ impl<K, V, E> ValueDeserializer<E> for HashMap<K, V>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// A helper deserializer that deserializes a map using a `MapVisitor`.
|
||||
pub struct MapVisitorDeserializer<V_, E> {
|
||||
pub struct MapVisitorDeserializer<V_> {
|
||||
visitor: V_,
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<V_, E> MapVisitorDeserializer<V_, E>
|
||||
where V_: de::MapVisitor<Error = E>,
|
||||
E: de::Error
|
||||
{
|
||||
impl<V_> MapVisitorDeserializer<V_> {
|
||||
/// Construct a new `MapVisitorDeserializer<V_, E>`.
|
||||
pub fn new(visitor: V_) -> Self {
|
||||
MapVisitorDeserializer {
|
||||
visitor: visitor,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V_, E> de::Deserializer for MapVisitorDeserializer<V_, E>
|
||||
where V_: de::MapVisitor<Error = E>,
|
||||
E: de::Error
|
||||
impl<'de, V_> de::Deserializer<'de> for MapVisitorDeserializer<V_>
|
||||
where V_: de::MapVisitor<'de>
|
||||
{
|
||||
type Error = E;
|
||||
type Error = V_::Error;
|
||||
|
||||
fn deserialize<V: de::Visitor>(self, visitor: V) -> Result<V::Value, Self::Error> {
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_map(self.visitor)
|
||||
}
|
||||
|
||||
@ -965,7 +959,7 @@ impl<V_, E> de::Deserializer for MapVisitorDeserializer<V_, E>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
impl<'a, E> ValueDeserializer<E> for bytes::Bytes<'a>
|
||||
impl<'de, 'a, E> ValueDeserializer<'de, E> for bytes::Bytes<'a>
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = BytesDeserializer<'a, E>;
|
||||
@ -984,13 +978,13 @@ pub struct BytesDeserializer<'a, E> {
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, E> de::Deserializer for BytesDeserializer<'a, E>
|
||||
impl<'de, 'a, E> de::Deserializer<'de> for BytesDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_bytes(self.value)
|
||||
}
|
||||
@ -1005,7 +999,7 @@ impl<'a, E> de::Deserializer for BytesDeserializer<'a, E>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<E> ValueDeserializer<E> for bytes::ByteBuf
|
||||
impl<'de, E> ValueDeserializer<'de, E> for bytes::ByteBuf
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = ByteBufDeserializer<E>;
|
||||
@ -1026,13 +1020,13 @@ pub struct ByteBufDeserializer<E> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
impl<E> de::Deserializer for ByteBufDeserializer<E>
|
||||
impl<'de, E> de::Deserializer<'de> for ByteBufDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
visitor.visit_byte_buf(self.value)
|
||||
}
|
||||
@ -1058,7 +1052,7 @@ mod private {
|
||||
(t, UnitOnly { marker: PhantomData })
|
||||
}
|
||||
|
||||
impl<E> de::VariantVisitor for UnitOnly<E>
|
||||
impl<'de, E> de::VariantVisitor<'de> for UnitOnly<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
@ -1068,13 +1062,13 @@ mod private {
|
||||
}
|
||||
|
||||
fn visit_newtype_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error>
|
||||
where T: de::DeserializeSeed
|
||||
where T: de::DeserializeSeed<'de>
|
||||
{
|
||||
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"newtype variant"))
|
||||
}
|
||||
|
||||
fn visit_tuple<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"tuple variant"))
|
||||
}
|
||||
@ -1083,7 +1077,7 @@ mod private {
|
||||
_fields: &'static [&'static str],
|
||||
_visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
where V: de::Visitor<'de>
|
||||
{
|
||||
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"struct variant"))
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ macro_rules! forward_to_deserialize_method {
|
||||
($func:ident($($arg:ty),*)) => {
|
||||
#[inline]
|
||||
fn $func<__V>(self, $(_: $arg,)* visitor: __V) -> ::std::result::Result<__V::Value, Self::Error>
|
||||
where __V: $crate::de::Visitor
|
||||
where __V: $crate::de::Visitor<'de>
|
||||
{
|
||||
self.deserialize(visitor)
|
||||
}
|
||||
@ -19,7 +19,7 @@ macro_rules! forward_to_deserialize_method {
|
||||
($func:ident($($arg:ty),*)) => {
|
||||
#[inline]
|
||||
fn $func<__V>(self, $(_: $arg,)* visitor: __V) -> ::core::result::Result<__V::Value, Self::Error>
|
||||
where __V: $crate::de::Visitor
|
||||
where __V: $crate::de::Visitor<'de>
|
||||
{
|
||||
self.deserialize(visitor)
|
||||
}
|
||||
@ -135,15 +135,15 @@ macro_rules! forward_to_deserialize_helper {
|
||||
/// # #[macro_use] extern crate serde;
|
||||
/// # use serde::de::{value, Deserializer, Visitor};
|
||||
/// # pub struct MyDeserializer;
|
||||
/// # impl Deserializer for MyDeserializer {
|
||||
/// # impl<'de> Deserializer<'de> for MyDeserializer {
|
||||
/// # type Error = value::Error;
|
||||
/// # fn deserialize<V>(self, _: V) -> Result<V::Value, Self::Error>
|
||||
/// # where V: Visitor
|
||||
/// # where V: Visitor<'de>
|
||||
/// # { unimplemented!() }
|
||||
/// #
|
||||
/// #[inline]
|
||||
/// fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
/// where V: Visitor
|
||||
/// where V: Visitor<'de>
|
||||
/// {
|
||||
/// self.deserialize(visitor)
|
||||
/// }
|
||||
@ -164,10 +164,10 @@ macro_rules! forward_to_deserialize_helper {
|
||||
/// # #[macro_use] extern crate serde;
|
||||
/// # use serde::de::{value, Deserializer, Visitor};
|
||||
/// # pub struct MyDeserializer;
|
||||
/// impl Deserializer for MyDeserializer {
|
||||
/// impl<'de> Deserializer<'de> for MyDeserializer {
|
||||
/// # type Error = value::Error;
|
||||
/// fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
/// where V: Visitor
|
||||
/// where V: Visitor<'de>
|
||||
/// {
|
||||
/// /* ... */
|
||||
/// # let _ = visitor;
|
||||
@ -182,6 +182,10 @@ macro_rules! forward_to_deserialize_helper {
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// The macro assumes the convention that your `Deserializer` lifetime parameter
|
||||
/// is called `'de`. It will not work if the `Deserializer` lifetime parameter
|
||||
/// is called something different.
|
||||
#[macro_export]
|
||||
macro_rules! forward_to_deserialize {
|
||||
($($func:ident)*) => {
|
||||
|
@ -6,28 +6,8 @@ use internals::ast::Item;
|
||||
use internals::attr;
|
||||
|
||||
macro_rules! path {
|
||||
($first:ident $(:: $rest:ident)*) => {
|
||||
syn::Path {
|
||||
global: false,
|
||||
segments: vec![
|
||||
stringify!($first).into(),
|
||||
$(
|
||||
stringify!($rest).into(),
|
||||
)*
|
||||
],
|
||||
}
|
||||
};
|
||||
|
||||
(::$first:ident $(:: $rest:ident)*) => {
|
||||
syn::Path {
|
||||
global: true,
|
||||
segments: vec![
|
||||
stringify!($first).into(),
|
||||
$(
|
||||
stringify!($rest).into(),
|
||||
)*
|
||||
],
|
||||
}
|
||||
($($path:tt)+) => {
|
||||
syn::parse_path(stringify!($($path)+)).unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use syn::{self, Ident};
|
||||
use quote::{self, Tokens};
|
||||
use quote::{self, Tokens, ToTokens};
|
||||
|
||||
use bound;
|
||||
use fragment::{Fragment, Expr, Stmts, Match};
|
||||
@ -17,7 +17,7 @@ pub fn expand_derive_deserialize(item: &syn::DeriveInput) -> Result<Tokens, Stri
|
||||
|
||||
let ident = &item.ident;
|
||||
let generics = build_generics(&item);
|
||||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
let (de_impl_generics, _, ty_generics, where_clause) = split_with_de_lifetime(&generics);
|
||||
let dummy_const = Ident::new(format!("_IMPL_DESERIALIZE_FOR_{}", ident));
|
||||
let body = Stmts(deserialize_body(&item, &generics));
|
||||
|
||||
@ -26,9 +26,9 @@ pub fn expand_derive_deserialize(item: &syn::DeriveInput) -> Result<Tokens, Stri
|
||||
const #dummy_const: () = {
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl #impl_generics _serde::Deserialize for #ident #ty_generics #where_clause {
|
||||
impl #de_impl_generics _serde::Deserialize<'de> for #ident #ty_generics #where_clause {
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error>
|
||||
where __D: _serde::Deserializer
|
||||
where __D: _serde::Deserializer<'de>
|
||||
{
|
||||
#body
|
||||
}
|
||||
@ -60,7 +60,7 @@ fn build_generics(item: &Item) -> syn::Generics {
|
||||
bound::with_bound(item,
|
||||
&generics,
|
||||
needs_deserialize_bound,
|
||||
&path!(_serde::Deserialize));
|
||||
&path!(_serde::Deserialize<'de>));
|
||||
|
||||
bound::with_bound(item,
|
||||
&generics,
|
||||
@ -136,7 +136,7 @@ fn deserialize_unit_struct(ident: &syn::Ident, item_attrs: &attr::Item) -> Fragm
|
||||
quote_block! {
|
||||
struct __Visitor;
|
||||
|
||||
impl _serde::de::Visitor for __Visitor {
|
||||
impl<'de> _serde::de::Visitor<'de> for __Visitor {
|
||||
type Value = #ident;
|
||||
|
||||
fn expecting(&self, formatter: &mut _serde::export::fmt::Formatter) -> _serde::export::fmt::Result {
|
||||
@ -152,7 +152,7 @@ fn deserialize_unit_struct(ident: &syn::Ident, item_attrs: &attr::Item) -> Fragm
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<__V>(self, _: __V) -> _serde::export::Result<#ident, __V::Error>
|
||||
where __V: _serde::de::SeqVisitor
|
||||
where __V: _serde::de::SeqVisitor<'de>
|
||||
{
|
||||
_serde::export::Ok(#ident)
|
||||
}
|
||||
@ -169,7 +169,7 @@ fn deserialize_tuple(ident: &syn::Ident,
|
||||
item_attrs: &attr::Item,
|
||||
deserializer: Option<Tokens>)
|
||||
-> Fragment {
|
||||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) = split_with_de_lifetime(generics);
|
||||
|
||||
let is_enum = variant_ident.is_some();
|
||||
let type_path = match variant_ident {
|
||||
@ -192,7 +192,10 @@ fn deserialize_tuple(ident: &syn::Ident,
|
||||
let visit_seq = Stmts(deserialize_seq(ident, &type_path, generics, fields, false, item_attrs));
|
||||
|
||||
let visitor_expr = quote! {
|
||||
__Visitor { marker: _serde::export::PhantomData::<#ident #ty_generics> }
|
||||
__Visitor {
|
||||
marker: _serde::export::PhantomData::<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
}
|
||||
};
|
||||
let dispatch = if let Some(deserializer) = deserializer {
|
||||
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #nfields, #visitor_expr))
|
||||
@ -214,11 +217,12 @@ fn deserialize_tuple(ident: &syn::Ident,
|
||||
};
|
||||
|
||||
quote_block! {
|
||||
struct __Visitor #impl_generics #where_clause {
|
||||
struct __Visitor #de_impl_generics #where_clause {
|
||||
marker: _serde::export::PhantomData<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData<&'de ()>,
|
||||
}
|
||||
|
||||
impl #impl_generics _serde::de::Visitor for __Visitor #ty_generics #where_clause {
|
||||
impl #de_impl_generics _serde::de::Visitor<'de> for __Visitor #de_ty_generics #where_clause {
|
||||
type Value = #ident #ty_generics;
|
||||
|
||||
fn expecting(&self, formatter: &mut _serde::export::fmt::Formatter) -> _serde::export::fmt::Result {
|
||||
@ -229,7 +233,7 @@ fn deserialize_tuple(ident: &syn::Ident,
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<__V>(self, #visitor_var: __V) -> _serde::export::Result<Self::Value, __V::Error>
|
||||
where __V: _serde::de::SeqVisitor
|
||||
where __V: _serde::de::SeqVisitor<'de>
|
||||
{
|
||||
#visit_seq
|
||||
}
|
||||
@ -332,7 +336,7 @@ fn deserialize_newtype_struct(ident: &syn::Ident,
|
||||
quote! {
|
||||
#[inline]
|
||||
fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::export::Result<Self::Value, __E::Error>
|
||||
where __E: _serde::Deserializer
|
||||
where __E: _serde::Deserializer<'de>
|
||||
{
|
||||
_serde::export::Ok(#type_path(#value))
|
||||
}
|
||||
@ -349,7 +353,7 @@ fn deserialize_struct(ident: &syn::Ident,
|
||||
let is_enum = variant_ident.is_some();
|
||||
let is_untagged = deserializer.is_some();
|
||||
|
||||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) = split_with_de_lifetime(generics);
|
||||
|
||||
let type_path = match variant_ident {
|
||||
Some(variant_ident) => quote!(#ident::#variant_ident),
|
||||
@ -369,7 +373,10 @@ fn deserialize_struct(ident: &syn::Ident,
|
||||
let visit_map = Stmts(visit_map);
|
||||
|
||||
let visitor_expr = quote! {
|
||||
__Visitor { marker: _serde::export::PhantomData::<#ident #ty_generics> }
|
||||
__Visitor {
|
||||
marker: _serde::export::PhantomData::<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
}
|
||||
};
|
||||
let dispatch = if let Some(deserializer) = deserializer {
|
||||
quote! {
|
||||
@ -400,7 +407,7 @@ fn deserialize_struct(ident: &syn::Ident,
|
||||
Some(quote! {
|
||||
#[inline]
|
||||
fn visit_seq<__V>(self, #visitor_var: __V) -> _serde::export::Result<Self::Value, __V::Error>
|
||||
where __V: _serde::de::SeqVisitor
|
||||
where __V: _serde::de::SeqVisitor<'de>
|
||||
{
|
||||
#visit_seq
|
||||
}
|
||||
@ -410,11 +417,12 @@ fn deserialize_struct(ident: &syn::Ident,
|
||||
quote_block! {
|
||||
#field_visitor
|
||||
|
||||
struct __Visitor #impl_generics #where_clause {
|
||||
struct __Visitor #de_impl_generics #where_clause {
|
||||
marker: _serde::export::PhantomData<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData<&'de ()>,
|
||||
}
|
||||
|
||||
impl #generics _serde::de::Visitor for __Visitor #ty_generics #where_clause {
|
||||
impl #de_impl_generics _serde::de::Visitor<'de> for __Visitor #de_ty_generics #where_clause {
|
||||
type Value = #ident #ty_generics;
|
||||
|
||||
fn expecting(&self, formatter: &mut _serde::export::fmt::Formatter) -> _serde::export::fmt::Result {
|
||||
@ -425,7 +433,7 @@ fn deserialize_struct(ident: &syn::Ident,
|
||||
|
||||
#[inline]
|
||||
fn visit_map<__V>(self, mut __visitor: __V) -> _serde::export::Result<Self::Value, __V::Error>
|
||||
where __V: _serde::de::MapVisitor
|
||||
where __V: _serde::de::MapVisitor<'de>
|
||||
{
|
||||
#visit_map
|
||||
}
|
||||
@ -472,7 +480,7 @@ fn deserialize_externally_tagged_enum(ident: &syn::Ident,
|
||||
variants: &[Variant],
|
||||
item_attrs: &attr::Item)
|
||||
-> Fragment {
|
||||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) = split_with_de_lifetime(generics);
|
||||
|
||||
let type_name = item_attrs.name().deserialize_name();
|
||||
|
||||
@ -533,11 +541,12 @@ fn deserialize_externally_tagged_enum(ident: &syn::Ident,
|
||||
quote_block! {
|
||||
#variant_visitor
|
||||
|
||||
struct __Visitor #impl_generics #where_clause {
|
||||
struct __Visitor #de_impl_generics #where_clause {
|
||||
marker: _serde::export::PhantomData<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData<&'de ()>,
|
||||
}
|
||||
|
||||
impl #generics _serde::de::Visitor for __Visitor #ty_generics #where_clause {
|
||||
impl #de_impl_generics _serde::de::Visitor<'de> for __Visitor #de_ty_generics #where_clause {
|
||||
type Value = #ident #ty_generics;
|
||||
|
||||
fn expecting(&self, formatter: &mut _serde::export::fmt::Formatter) -> _serde::export::fmt::Result {
|
||||
@ -545,7 +554,7 @@ fn deserialize_externally_tagged_enum(ident: &syn::Ident,
|
||||
}
|
||||
|
||||
fn visit_enum<__V>(self, __visitor: __V) -> _serde::export::Result<Self::Value, __V::Error>
|
||||
where __V: _serde::de::EnumVisitor
|
||||
where __V: _serde::de::EnumVisitor<'de>
|
||||
{
|
||||
#match_variant
|
||||
}
|
||||
@ -556,6 +565,7 @@ fn deserialize_externally_tagged_enum(ident: &syn::Ident,
|
||||
_serde::Deserializer::deserialize_enum(__deserializer, #type_name, VARIANTS,
|
||||
__Visitor {
|
||||
marker: _serde::export::PhantomData::<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -623,7 +633,7 @@ fn deserialize_adjacently_tagged_enum(ident: &syn::Ident,
|
||||
tag: &str,
|
||||
content: &str)
|
||||
-> Fragment {
|
||||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) = split_with_de_lifetime(generics);
|
||||
|
||||
let variant_names_idents: Vec<_> = variants.iter()
|
||||
.enumerate()
|
||||
@ -724,16 +734,17 @@ fn deserialize_adjacently_tagged_enum(ident: &syn::Ident,
|
||||
|
||||
#variants_stmt
|
||||
|
||||
struct __Seed #impl_generics #where_clause {
|
||||
struct __Seed #de_impl_generics #where_clause {
|
||||
field: __Field,
|
||||
marker: _serde::export::PhantomData<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData<&'de ()>,
|
||||
}
|
||||
|
||||
impl #impl_generics _serde::de::DeserializeSeed for __Seed #ty_generics #where_clause {
|
||||
impl #de_impl_generics _serde::de::DeserializeSeed<'de> for __Seed #de_ty_generics #where_clause {
|
||||
type Value = #ident #ty_generics;
|
||||
|
||||
fn deserialize<__D>(self, __deserializer: __D) -> _serde::export::Result<Self::Value, __D::Error>
|
||||
where __D: _serde::Deserializer
|
||||
where __D: _serde::Deserializer<'de>
|
||||
{
|
||||
match self.field {
|
||||
#(#variant_arms)*
|
||||
@ -741,11 +752,12 @@ fn deserialize_adjacently_tagged_enum(ident: &syn::Ident,
|
||||
}
|
||||
}
|
||||
|
||||
struct __Visitor #impl_generics #where_clause {
|
||||
struct __Visitor #de_impl_generics #where_clause {
|
||||
marker: _serde::export::PhantomData<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData<&'de ()>,
|
||||
}
|
||||
|
||||
impl #impl_generics _serde::de::Visitor for __Visitor #ty_generics #where_clause {
|
||||
impl #de_impl_generics _serde::de::Visitor<'de> for __Visitor #de_ty_generics #where_clause {
|
||||
type Value = #ident #ty_generics;
|
||||
|
||||
fn expecting(&self, formatter: &mut _serde::export::fmt::Formatter) -> _serde::export::fmt::Result {
|
||||
@ -753,7 +765,7 @@ fn deserialize_adjacently_tagged_enum(ident: &syn::Ident,
|
||||
}
|
||||
|
||||
fn visit_map<__V>(self, mut __visitor: __V) -> _serde::export::Result<Self::Value, __V::Error>
|
||||
where __V: _serde::de::MapVisitor
|
||||
where __V: _serde::de::MapVisitor<'de>
|
||||
{
|
||||
// Visit the first key.
|
||||
match try!(_serde::de::MapVisitor::visit_key_seed(&mut __visitor, #tag_or_content)) {
|
||||
@ -769,7 +781,12 @@ fn deserialize_adjacently_tagged_enum(ident: &syn::Ident,
|
||||
}
|
||||
// Second key is the content.
|
||||
_serde::export::Some(_serde::de::private::TagOrContentField::Content) => {
|
||||
let __ret = try!(_serde::de::MapVisitor::visit_value_seed(&mut __visitor, __Seed { field: __field, marker: _serde::export::PhantomData }));
|
||||
let __ret = try!(_serde::de::MapVisitor::visit_value_seed(&mut __visitor,
|
||||
__Seed {
|
||||
field: __field,
|
||||
marker: _serde::export::PhantomData,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
}));
|
||||
// Visit the third key, hopefully there isn't one.
|
||||
#visit_third_key
|
||||
}
|
||||
@ -812,13 +829,18 @@ fn deserialize_adjacently_tagged_enum(ident: &syn::Ident,
|
||||
}
|
||||
|
||||
fn visit_seq<__V>(self, mut __visitor: __V) -> _serde::export::Result<Self::Value, __V::Error>
|
||||
where __V: _serde::de::SeqVisitor
|
||||
where __V: _serde::de::SeqVisitor<'de>
|
||||
{
|
||||
// Visit the first element - the tag.
|
||||
match try!(_serde::de::SeqVisitor::visit(&mut __visitor)) {
|
||||
_serde::export::Some(__field) => {
|
||||
// Visit the second element - the content.
|
||||
match try!(_serde::de::SeqVisitor::visit_seed(&mut __visitor, __Seed { field: __field, marker: _serde::export::PhantomData })) {
|
||||
match try!(_serde::de::SeqVisitor::visit_seed(&mut __visitor,
|
||||
__Seed {
|
||||
field: __field,
|
||||
marker: _serde::export::PhantomData,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
})) {
|
||||
_serde::export::Some(__ret) => _serde::export::Ok(__ret),
|
||||
// There is no second element.
|
||||
_serde::export::None => {
|
||||
@ -836,7 +858,10 @@ fn deserialize_adjacently_tagged_enum(ident: &syn::Ident,
|
||||
|
||||
const FIELDS: &'static [&'static str] = &[#tag, #content];
|
||||
_serde::Deserializer::deserialize_struct(__deserializer, #type_name, FIELDS,
|
||||
__Visitor { marker: _serde::export::PhantomData::<#ident #ty_generics> })
|
||||
__Visitor {
|
||||
marker: _serde::export::PhantomData::<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1111,14 +1136,14 @@ fn deserialize_field_visitor(fields: Vec<(String, Ident)>,
|
||||
#ignore_variant
|
||||
}
|
||||
|
||||
impl _serde::Deserialize for __Field {
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<__Field, __D::Error>
|
||||
where __D: _serde::Deserializer
|
||||
where __D: _serde::Deserializer<'de>
|
||||
{
|
||||
struct __FieldVisitor;
|
||||
|
||||
impl _serde::de::Visitor for __FieldVisitor {
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
|
||||
fn expecting(&self, formatter: &mut _serde::export::fmt::Formatter) -> _serde::export::fmt::Result {
|
||||
@ -1334,27 +1359,29 @@ fn wrap_deserialize_with(ident: &syn::Ident,
|
||||
field_ty: &syn::Ty,
|
||||
deserialize_with: &syn::Path)
|
||||
-> (Tokens, Tokens) {
|
||||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) = split_with_de_lifetime(generics);
|
||||
|
||||
let wrapper = quote! {
|
||||
struct __DeserializeWith #impl_generics #where_clause {
|
||||
struct __DeserializeWith #de_impl_generics #where_clause {
|
||||
value: #field_ty,
|
||||
phantom: _serde::export::PhantomData<#ident #ty_generics>,
|
||||
lifetime: _serde::export::PhantomData<&'de ()>,
|
||||
}
|
||||
|
||||
impl #impl_generics _serde::Deserialize for __DeserializeWith #ty_generics #where_clause {
|
||||
impl #de_impl_generics _serde::Deserialize<'de> for __DeserializeWith #de_ty_generics #where_clause {
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::export::Result<Self, __D::Error>
|
||||
where __D: _serde::Deserializer
|
||||
where __D: _serde::Deserializer<'de>
|
||||
{
|
||||
_serde::export::Ok(__DeserializeWith {
|
||||
value: try!(#deserialize_with(__deserializer)),
|
||||
phantom: _serde::export::PhantomData,
|
||||
lifetime: _serde::export::PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let wrapper_ty = quote!(__DeserializeWith #ty_generics);
|
||||
let wrapper_ty = quote!(__DeserializeWith #de_ty_generics);
|
||||
|
||||
(wrapper, wrapper_ty)
|
||||
}
|
||||
@ -1414,3 +1441,32 @@ fn check_no_str(cx: &internals::Ctxt, item: &Item) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DeImplGenerics<'a>(&'a syn::Generics);
|
||||
|
||||
impl<'a> ToTokens for DeImplGenerics<'a> {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
let mut generics = self.0.clone();
|
||||
generics.lifetimes.insert(0, syn::LifetimeDef::new("'de"));
|
||||
let (impl_generics, _, _) = generics.split_for_impl();
|
||||
impl_generics.to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
struct DeTyGenerics<'a>(&'a syn::Generics);
|
||||
|
||||
impl<'a> ToTokens for DeTyGenerics<'a> {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
let mut generics = self.0.clone();
|
||||
generics.lifetimes.insert(0, syn::LifetimeDef::new("'de"));
|
||||
let (_, ty_generics, _) = generics.split_for_impl();
|
||||
ty_generics.to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
fn split_with_de_lifetime(generics: &syn::Generics) -> (DeImplGenerics, DeTyGenerics, syn::TyGenerics, &syn::WhereClause) {
|
||||
let de_impl_generics = DeImplGenerics(generics);
|
||||
let de_ty_generics = DeTyGenerics(generics);
|
||||
let (_, ty_generics, where_clause) = generics.split_for_impl();
|
||||
(de_impl_generics, de_ty_generics, ty_generics, where_clause)
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ use token::Token;
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// Runs both `assert_ser_tokens` and `assert_de_tokens`.
|
||||
pub fn assert_tokens<T>(value: &T, tokens: &[Token<'static>])
|
||||
where T: Serialize + Deserialize + PartialEq + Debug
|
||||
pub fn assert_tokens<'de, T>(value: &T, tokens: &[Token<'static>])
|
||||
where T: Serialize + Deserialize<'de> + PartialEq + Debug
|
||||
{
|
||||
assert_ser_tokens(value, tokens);
|
||||
assert_de_tokens(value, tokens);
|
||||
@ -35,8 +35,8 @@ pub fn assert_ser_tokens_error<T>(value: &T, tokens: &[Token], error: Error)
|
||||
}
|
||||
|
||||
/// Asserts that the given `tokens` deserialize into `value`.
|
||||
pub fn assert_de_tokens<T>(value: &T, tokens: &[Token<'static>])
|
||||
where T: Deserialize + PartialEq + Debug
|
||||
pub fn assert_de_tokens<'de, T>(value: &T, tokens: &[Token<'static>])
|
||||
where T: Deserialize<'de> + PartialEq + Debug
|
||||
{
|
||||
let mut de = Deserializer::new(tokens.to_vec().into_iter());
|
||||
let v: Result<T, Error> = Deserialize::deserialize(&mut de);
|
||||
@ -45,8 +45,8 @@ pub fn assert_de_tokens<T>(value: &T, tokens: &[Token<'static>])
|
||||
}
|
||||
|
||||
/// Asserts that the given `tokens` yield `error` when deserializing.
|
||||
pub fn assert_de_tokens_error<T>(tokens: &[Token<'static>], error: Error)
|
||||
where T: Deserialize + PartialEq + Debug
|
||||
pub fn assert_de_tokens_error<'de, T>(tokens: &[Token<'static>], error: Error)
|
||||
where T: Deserialize<'de> + PartialEq + Debug
|
||||
{
|
||||
let mut de = Deserializer::new(tokens.to_vec().into_iter());
|
||||
let v: Result<T, Error> = Deserialize::deserialize(&mut de);
|
||||
|
@ -41,13 +41,13 @@ impl<I> Deserializer<I>
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_seq<V>(&mut self,
|
||||
fn visit_seq<'de, V>(&mut self,
|
||||
len: Option<usize>,
|
||||
sep: Token<'static>,
|
||||
end: Token<'static>,
|
||||
visitor: V)
|
||||
-> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
let value = try!(visitor.visit_seq(DeserializerSeqVisitor {
|
||||
de: self,
|
||||
@ -59,13 +59,13 @@ impl<I> Deserializer<I>
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn visit_map<V>(&mut self,
|
||||
fn visit_map<'de, V>(&mut self,
|
||||
len: Option<usize>,
|
||||
sep: Token<'static>,
|
||||
end: Token<'static>,
|
||||
visitor: V)
|
||||
-> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
let value = try!(visitor.visit_map(DeserializerMapVisitor {
|
||||
de: self,
|
||||
@ -78,7 +78,7 @@ impl<I> Deserializer<I>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
impl<'de, 'a, I> de::Deserializer<'de> for &'a mut Deserializer<I>
|
||||
where I: Iterator<Item = Token<'static>>
|
||||
{
|
||||
type Error = Error;
|
||||
@ -89,7 +89,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
}
|
||||
|
||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.next() {
|
||||
Some(Token::Bool(v)) => visitor.visit_bool(v),
|
||||
@ -148,7 +148,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
/// Hook into `Option` deserializing so we can treat `Unit` as a
|
||||
/// `None`, or a regular value as `Some(value)`.
|
||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.peek() {
|
||||
Some(&Token::Unit) |
|
||||
@ -170,7 +170,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.peek() {
|
||||
Some(&Token::EnumStart(n)) if name == n => {
|
||||
@ -193,7 +193,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
}
|
||||
|
||||
fn deserialize_unit_struct<V>(self, name: &str, visitor: V) -> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.peek() {
|
||||
Some(&Token::UnitStruct(n)) => {
|
||||
@ -210,7 +210,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
}
|
||||
|
||||
fn deserialize_newtype_struct<V>(self, name: &str, visitor: V) -> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.peek() {
|
||||
Some(&Token::StructNewType(n)) => {
|
||||
@ -227,7 +227,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
}
|
||||
|
||||
fn deserialize_seq_fixed_size<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.peek() {
|
||||
Some(&Token::SeqArrayStart(_)) => {
|
||||
@ -240,7 +240,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
}
|
||||
|
||||
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.peek() {
|
||||
Some(&Token::Unit) |
|
||||
@ -277,7 +277,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
len: usize,
|
||||
visitor: V)
|
||||
-> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.peek() {
|
||||
Some(&Token::Unit) => {
|
||||
@ -325,7 +325,7 @@ impl<'a, I> de::Deserializer for &'a mut Deserializer<I>
|
||||
fields: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.tokens.peek() {
|
||||
Some(&Token::StructStart(n, _)) => {
|
||||
@ -360,13 +360,13 @@ struct DeserializerSeqVisitor<'a, I: 'a>
|
||||
end: Token<'static>,
|
||||
}
|
||||
|
||||
impl<'a, I> SeqVisitor for DeserializerSeqVisitor<'a, I>
|
||||
impl<'de, 'a, I> SeqVisitor<'de> for DeserializerSeqVisitor<'a, I>
|
||||
where I: Iterator<Item = Token<'static>>
|
||||
{
|
||||
type Error = Error;
|
||||
|
||||
fn visit_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Error>
|
||||
where T: DeserializeSeed
|
||||
where T: DeserializeSeed<'de>
|
||||
{
|
||||
if self.de.tokens.peek() == Some(&self.end) {
|
||||
return Ok(None);
|
||||
@ -398,13 +398,13 @@ struct DeserializerMapVisitor<'a, I: 'a>
|
||||
end: Token<'static>,
|
||||
}
|
||||
|
||||
impl<'a, I> MapVisitor for DeserializerMapVisitor<'a, I>
|
||||
impl<'de, 'a, I> MapVisitor<'de> for DeserializerMapVisitor<'a, I>
|
||||
where I: Iterator<Item = Token<'static>>
|
||||
{
|
||||
type Error = Error;
|
||||
|
||||
fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error>
|
||||
where K: DeserializeSeed
|
||||
where K: DeserializeSeed<'de>
|
||||
{
|
||||
if self.de.tokens.peek() == Some(&self.end) {
|
||||
return Ok(None);
|
||||
@ -420,7 +420,7 @@ impl<'a, I> MapVisitor for DeserializerMapVisitor<'a, I>
|
||||
}
|
||||
|
||||
fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error>
|
||||
where V: DeserializeSeed
|
||||
where V: DeserializeSeed<'de>
|
||||
{
|
||||
seed.deserialize(&mut *self.de)
|
||||
}
|
||||
@ -439,14 +439,14 @@ struct DeserializerEnumVisitor<'a, I: 'a>
|
||||
de: &'a mut Deserializer<I>,
|
||||
}
|
||||
|
||||
impl<'a, I> EnumVisitor for DeserializerEnumVisitor<'a, I>
|
||||
impl<'de, 'a, I> EnumVisitor<'de> for DeserializerEnumVisitor<'a, I>
|
||||
where I: Iterator<Item = Token<'static>>
|
||||
{
|
||||
type Error = Error;
|
||||
type Variant = Self;
|
||||
|
||||
fn visit_variant_seed<V>(self, seed: V) -> Result<(V::Value, Self), Error>
|
||||
where V: DeserializeSeed
|
||||
where V: DeserializeSeed<'de>
|
||||
{
|
||||
match self.de.tokens.peek() {
|
||||
Some(&Token::EnumUnit(_, v)) |
|
||||
@ -466,7 +466,7 @@ impl<'a, I> EnumVisitor for DeserializerEnumVisitor<'a, I>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I> VariantVisitor for DeserializerEnumVisitor<'a, I>
|
||||
impl<'de, 'a, I> VariantVisitor<'de> for DeserializerEnumVisitor<'a, I>
|
||||
where I: Iterator<Item = Token<'static>>
|
||||
{
|
||||
type Error = Error;
|
||||
@ -483,7 +483,7 @@ impl<'a, I> VariantVisitor for DeserializerEnumVisitor<'a, I>
|
||||
}
|
||||
|
||||
fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
|
||||
where T: DeserializeSeed
|
||||
where T: DeserializeSeed<'de>
|
||||
{
|
||||
match self.de.tokens.peek() {
|
||||
Some(&Token::EnumNewType(_, _)) => {
|
||||
@ -496,7 +496,7 @@ impl<'a, I> VariantVisitor for DeserializerEnumVisitor<'a, I>
|
||||
}
|
||||
|
||||
fn visit_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.de.tokens.peek() {
|
||||
Some(&Token::EnumSeqStart(_, _, enum_len)) => {
|
||||
@ -523,7 +523,7 @@ impl<'a, I> VariantVisitor for DeserializerEnumVisitor<'a, I>
|
||||
}
|
||||
|
||||
fn visit_struct<V>(self, fields: &'static [&'static str], visitor: V) -> Result<V::Value, Error>
|
||||
where V: Visitor
|
||||
where V: Visitor<'de>
|
||||
{
|
||||
match self.de.tokens.peek() {
|
||||
Some(&Token::EnumMapStart(_, _, enum_len)) => {
|
||||
@ -573,13 +573,13 @@ impl<'a, I: 'a> EnumMapVisitor<'a, I>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I: 'a> MapVisitor for EnumMapVisitor<'a, I>
|
||||
impl<'de, 'a, I: 'a> MapVisitor<'de> for EnumMapVisitor<'a, I>
|
||||
where I: Iterator<Item = Token<'static>>
|
||||
{
|
||||
type Error = Error;
|
||||
|
||||
fn visit_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error>
|
||||
where K: DeserializeSeed
|
||||
where K: DeserializeSeed<'de>
|
||||
{
|
||||
match self.variant.take() {
|
||||
Some(variant) => seed.deserialize(variant.into_deserializer()).map(Some),
|
||||
@ -588,7 +588,7 @@ impl<'a, I: 'a> MapVisitor for EnumMapVisitor<'a, I>
|
||||
}
|
||||
|
||||
fn visit_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error>
|
||||
where V: DeserializeSeed
|
||||
where V: DeserializeSeed<'de>
|
||||
{
|
||||
match self.de.tokens.peek() {
|
||||
Some(&Token::EnumSeqSep) => {
|
||||
|
@ -28,8 +28,8 @@ trait SerializeWith: Sized {
|
||||
}
|
||||
|
||||
trait DeserializeWith: Sized {
|
||||
fn deserialize_with<D>(de: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer;
|
||||
fn deserialize_with<'de, D>(de: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer<'de>;
|
||||
}
|
||||
|
||||
impl MyDefault for i32 {
|
||||
@ -53,8 +53,8 @@ impl SerializeWith for i32 {
|
||||
}
|
||||
|
||||
impl DeserializeWith for i32 {
|
||||
fn deserialize_with<D>(de: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
fn deserialize_with<'de, D>(de: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
if try!(Deserialize::deserialize(de)) {
|
||||
Ok(123)
|
||||
@ -242,8 +242,8 @@ impl Default for NotDeserializeStruct {
|
||||
}
|
||||
|
||||
impl DeserializeWith for NotDeserializeStruct {
|
||||
fn deserialize_with<D>(_: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer
|
||||
fn deserialize_with<'de, D>(_: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
panic!()
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ extern crate serde_derive;
|
||||
|
||||
extern crate serde;
|
||||
use self::serde::ser::{Serialize, Serializer};
|
||||
use self::serde::de::{Deserialize, Deserializer};
|
||||
use self::serde::de::{DeserializeOwned, Deserializer};
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::marker::PhantomData;
|
||||
@ -64,15 +64,6 @@ fn test_gen() {
|
||||
}
|
||||
assert::<PhantomT<X>>();
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Bounds<T: Serialize + Deserialize> {
|
||||
t: T,
|
||||
option: Option<T>,
|
||||
boxed: Box<T>,
|
||||
option_boxed: Option<Box<T>>,
|
||||
}
|
||||
assert::<Bounds<i32>>();
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct NoBounds<T> {
|
||||
t: T,
|
||||
@ -206,7 +197,7 @@ fn test_gen() {
|
||||
assert::<CowStr>();
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(bound(deserialize = "T::Owned: Deserialize"))]
|
||||
#[serde(bound(deserialize = "T::Owned: DeserializeOwned"))]
|
||||
struct CowT<'a, T: ?Sized + 'a + ToOwned>(Cow<'a, T>);
|
||||
assert::<CowT<str>>();
|
||||
|
||||
@ -308,7 +299,7 @@ fn test_gen() {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn assert<T: Serialize + Deserialize>() {}
|
||||
fn assert<T: Serialize + DeserializeOwned>() {}
|
||||
fn assert_ser<T: Serialize>() {}
|
||||
|
||||
trait SerializeWith {
|
||||
@ -316,7 +307,7 @@ trait SerializeWith {
|
||||
}
|
||||
|
||||
trait DeserializeWith: Sized {
|
||||
fn deserialize_with<D: Deserializer>(_: D) -> StdResult<Self, D::Error>;
|
||||
fn deserialize_with<'de, D: Deserializer<'de>>(_: D) -> StdResult<Self, D::Error>;
|
||||
}
|
||||
|
||||
// Implements neither Serialize nor Deserialize
|
||||
@ -326,7 +317,7 @@ pub fn ser_x<S: Serializer>(_: &X, _: S) -> StdResult<S::Ok, S::Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn de_x<D: Deserializer>(_: D) -> StdResult<X, D::Error> {
|
||||
pub fn de_x<'de, D: Deserializer<'de>>(_: D) -> StdResult<X, D::Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@ -341,7 +332,7 @@ impl SerializeWith for X {
|
||||
}
|
||||
|
||||
impl DeserializeWith for X {
|
||||
fn deserialize_with<D: Deserializer>(_: D) -> StdResult<Self, D::Error> {
|
||||
fn deserialize_with<'de, D: Deserializer<'de>>(_: D) -> StdResult<Self, D::Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user