Format serde with rustfmt 0.8.0
This commit is contained in:
parent
6750fdaae1
commit
77ee306b57
@ -510,9 +510,9 @@ impl<T> Visitor for TaggedContentVisitor<T>
|
||||
None => Err(de::Error::missing_field(self.tag_name)),
|
||||
Some(tag) => {
|
||||
Ok(TaggedContent {
|
||||
tag: tag,
|
||||
content: Content::Map(vec),
|
||||
})
|
||||
tag: tag,
|
||||
content: Content::Map(vec),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -604,8 +604,10 @@ impl<E> Deserializer for ContentDeserializer<E>
|
||||
Ok(value)
|
||||
}
|
||||
Content::Map(v) => {
|
||||
let map = v.into_iter()
|
||||
.map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
|
||||
let map = v.into_iter().map(|(k, v)| {
|
||||
(ContentDeserializer::new(k),
|
||||
ContentDeserializer::new(v))
|
||||
});
|
||||
let mut map_visitor = de::value::MapDeserializer::new(map);
|
||||
let value = try!(visitor.visit_map(&mut map_visitor));
|
||||
try!(map_visitor.end());
|
||||
@ -632,8 +634,12 @@ impl<E> Deserializer for ContentDeserializer<E>
|
||||
visitor.visit_newtype_struct(self)
|
||||
}
|
||||
|
||||
fn deserialize_enum<V>(self, _name: &str, _variants: &'static [&'static str], visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor,
|
||||
fn deserialize_enum<V>(self,
|
||||
_name: &str,
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor
|
||||
{
|
||||
let (variant, value) = match self.content {
|
||||
Content::Map(value) => {
|
||||
@ -641,12 +647,14 @@ impl<E> Deserializer for ContentDeserializer<E>
|
||||
let (variant, value) = match iter.next() {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return Err(de::Error::invalid_value(de::Unexpected::Map, &"map with a single key"));
|
||||
return Err(de::Error::invalid_value(de::Unexpected::Map,
|
||||
&"map with a single key"));
|
||||
}
|
||||
};
|
||||
// enums are encoded in json as maps with a single key:value pair
|
||||
if iter.next().is_some() {
|
||||
return Err(de::Error::invalid_value(de::Unexpected::Map, &"map with a single key"));
|
||||
return Err(de::Error::invalid_value(de::Unexpected::Map,
|
||||
&"map with a single key"));
|
||||
}
|
||||
(variant, Some(value))
|
||||
}
|
||||
@ -657,10 +665,10 @@ impl<E> Deserializer for ContentDeserializer<E>
|
||||
};
|
||||
|
||||
visitor.visit_enum(EnumDeserializer {
|
||||
variant: variant,
|
||||
value: value,
|
||||
err: PhantomData,
|
||||
})
|
||||
variant: variant,
|
||||
value: value,
|
||||
err: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
forward_to_deserialize! {
|
||||
@ -680,30 +688,43 @@ impl<E> ContentDeserializer<E> {
|
||||
}
|
||||
}
|
||||
|
||||
struct EnumDeserializer<E> where E: de::Error {
|
||||
struct EnumDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
variant: Content,
|
||||
value: Option<Content>,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> de::EnumVisitor for EnumDeserializer<E> where E: de::Error {
|
||||
impl<E> de::EnumVisitor for EnumDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
type Variant = VariantDeserializer<Self::Error>;
|
||||
|
||||
fn visit_variant_seed<V>(self, seed: V) -> Result<(V::Value, VariantDeserializer<E>), Self::Error>
|
||||
where V: de::DeserializeSeed,
|
||||
fn visit_variant_seed<V>(self,
|
||||
seed: V)
|
||||
-> Result<(V::Value, VariantDeserializer<E>), Self::Error>
|
||||
where V: de::DeserializeSeed
|
||||
{
|
||||
let visitor = VariantDeserializer { value: self.value, err: PhantomData, };
|
||||
let visitor = VariantDeserializer {
|
||||
value: self.value,
|
||||
err: PhantomData,
|
||||
};
|
||||
seed.deserialize(ContentDeserializer::new(self.variant)).map(|v| (v, visitor))
|
||||
}
|
||||
}
|
||||
|
||||
struct VariantDeserializer<E> where E: de::Error {
|
||||
struct VariantDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
value: Option<Content>,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> de::VariantVisitor for VariantDeserializer<E> where E: de::Error {
|
||||
impl<E> de::VariantVisitor for VariantDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_unit(self) -> Result<(), E> {
|
||||
@ -722,11 +743,7 @@ impl<E> de::VariantVisitor for VariantDeserializer<E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_tuple<V>(
|
||||
self,
|
||||
_len: usize,
|
||||
visitor: V
|
||||
) -> Result<V::Value, Self::Error>
|
||||
fn visit_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
{
|
||||
match self.value {
|
||||
@ -734,15 +751,14 @@ impl<E> de::VariantVisitor for VariantDeserializer<E> where E: de::Error {
|
||||
de::Deserializer::deserialize(SeqDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"tuple variant")),
|
||||
None => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"tuple variant"))
|
||||
None => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"tuple variant")),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_struct<V>(
|
||||
self,
|
||||
_fields: &'static [&'static str],
|
||||
visitor: V
|
||||
) -> Result<V::Value, Self::Error>
|
||||
fn visit_struct<V>(self,
|
||||
_fields: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
{
|
||||
match self.value {
|
||||
@ -750,17 +766,21 @@ impl<E> de::VariantVisitor for VariantDeserializer<E> where E: de::Error {
|
||||
de::Deserializer::deserialize(MapDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"struct variant")),
|
||||
_ => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"struct variant"))
|
||||
_ => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"struct variant")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SeqDeserializer<E> where E: de::Error {
|
||||
struct SeqDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
iter: <Vec<Content> as IntoIterator>::IntoIter,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> SeqDeserializer<E> where E: de::Error {
|
||||
impl<E> SeqDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
fn new(vec: Vec<Content>) -> Self {
|
||||
SeqDeserializer {
|
||||
iter: vec.into_iter(),
|
||||
@ -769,12 +789,14 @@ impl<E> SeqDeserializer<E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::Deserializer for SeqDeserializer<E> where E: de::Error {
|
||||
impl<E> de::Deserializer 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
|
||||
{
|
||||
let len = self.iter.len();
|
||||
if len == 0 {
|
||||
@ -797,11 +819,13 @@ impl<E> de::Deserializer for SeqDeserializer<E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::SeqVisitor for SeqDeserializer<E> where E: de::Error {
|
||||
impl<E> de::SeqVisitor 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
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)).map(Some),
|
||||
@ -814,13 +838,17 @@ impl<E> de::SeqVisitor for SeqDeserializer<E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
struct MapDeserializer<E> where E: de::Error {
|
||||
struct MapDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
iter: <Vec<(Content, Content)> as IntoIterator>::IntoIter,
|
||||
value: Option<Content>,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> MapDeserializer<E> where E: de::Error {
|
||||
impl<E> MapDeserializer<E>
|
||||
where E: de::Error
|
||||
{
|
||||
fn new(map: Vec<(Content, Content)>) -> Self {
|
||||
MapDeserializer {
|
||||
iter: map.into_iter(),
|
||||
@ -830,11 +858,13 @@ impl<E> MapDeserializer<E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::MapVisitor for MapDeserializer<E> where E: de::Error {
|
||||
impl<E> de::MapVisitor 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
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some((key, value)) => {
|
||||
@ -846,7 +876,7 @@ impl<E> de::MapVisitor for MapDeserializer<E> where E: de::Error {
|
||||
}
|
||||
|
||||
fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
|
||||
where T: de::DeserializeSeed,
|
||||
where T: de::DeserializeSeed
|
||||
{
|
||||
match self.value.take() {
|
||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)),
|
||||
@ -859,12 +889,14 @@ impl<E> de::MapVisitor for MapDeserializer<E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> de::Deserializer for MapDeserializer<E> where E: de::Error {
|
||||
impl<E> de::Deserializer 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
|
||||
{
|
||||
visitor.visit_map(self)
|
||||
}
|
||||
@ -920,8 +952,9 @@ impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||
}
|
||||
Content::Map(ref v) => {
|
||||
let map = v.into_iter().map(|&(ref k, ref v)| {
|
||||
(ContentRefDeserializer::new(k), ContentRefDeserializer::new(v))
|
||||
});
|
||||
(ContentRefDeserializer::new(k),
|
||||
ContentRefDeserializer::new(v))
|
||||
});
|
||||
let mut map_visitor = de::value::MapDeserializer::new(map);
|
||||
let value = try!(visitor.visit_map(&mut map_visitor));
|
||||
try!(map_visitor.end());
|
||||
@ -948,8 +981,12 @@ impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||
visitor.visit_newtype_struct(self)
|
||||
}
|
||||
|
||||
fn deserialize_enum<V>(self, _name: &str, _variants: &'static [&'static str], visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: Visitor,
|
||||
fn deserialize_enum<V>(self,
|
||||
_name: &str,
|
||||
_variants: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: Visitor
|
||||
{
|
||||
let (variant, value) = match *self.content {
|
||||
Content::Map(ref value) => {
|
||||
@ -957,12 +994,14 @@ impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||
let &(ref variant, ref value) = match iter.next() {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return Err(de::Error::invalid_value(de::Unexpected::Map, &"map with a single key"));
|
||||
return Err(de::Error::invalid_value(de::Unexpected::Map,
|
||||
&"map with a single key"));
|
||||
}
|
||||
};
|
||||
// enums are encoded in json as maps with a single key:value pair
|
||||
if iter.next().is_some() {
|
||||
return Err(de::Error::invalid_value(de::Unexpected::Map, &"map with a single key"));
|
||||
return Err(de::Error::invalid_value(de::Unexpected::Map,
|
||||
&"map with a single key"));
|
||||
}
|
||||
(variant, Some(value))
|
||||
}
|
||||
@ -973,10 +1012,10 @@ impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||
};
|
||||
|
||||
visitor.visit_enum(EnumRefDeserializer {
|
||||
variant: variant,
|
||||
value: value,
|
||||
err: PhantomData,
|
||||
})
|
||||
variant: variant,
|
||||
value: value,
|
||||
err: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
forward_to_deserialize! {
|
||||
@ -996,30 +1035,41 @@ impl<'a, E> ContentRefDeserializer<'a, E> {
|
||||
}
|
||||
}
|
||||
|
||||
struct EnumRefDeserializer<'a, E> where E: de::Error {
|
||||
struct EnumRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
variant: &'a Content,
|
||||
value: Option<&'a Content>,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, E> de::EnumVisitor for EnumRefDeserializer<'a, E> where E: de::Error {
|
||||
impl<'a, E> de::EnumVisitor 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
|
||||
{
|
||||
let visitor = VariantRefDeserializer { value: self.value, err: PhantomData, };
|
||||
let visitor = VariantRefDeserializer {
|
||||
value: self.value,
|
||||
err: PhantomData,
|
||||
};
|
||||
seed.deserialize(ContentRefDeserializer::new(self.variant)).map(|v| (v, visitor))
|
||||
}
|
||||
}
|
||||
|
||||
struct VariantRefDeserializer<'a, E> where E: de::Error {
|
||||
struct VariantRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
value: Option<&'a Content>,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E> where E: de::Error {
|
||||
impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn visit_unit(self) -> Result<(), E> {
|
||||
@ -1038,11 +1088,7 @@ impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E> where E: de::Er
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_tuple<V>(
|
||||
self,
|
||||
_len: usize,
|
||||
visitor: V
|
||||
) -> Result<V::Value, Self::Error>
|
||||
fn visit_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
{
|
||||
match self.value {
|
||||
@ -1050,15 +1096,14 @@ impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E> where E: de::Er
|
||||
de::Deserializer::deserialize(SeqRefDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"tuple variant")),
|
||||
None => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"tuple variant"))
|
||||
None => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"tuple variant")),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_struct<V>(
|
||||
self,
|
||||
_fields: &'static [&'static str],
|
||||
visitor: V
|
||||
) -> Result<V::Value, Self::Error>
|
||||
fn visit_struct<V>(self,
|
||||
_fields: &'static [&'static str],
|
||||
visitor: V)
|
||||
-> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor
|
||||
{
|
||||
match self.value {
|
||||
@ -1066,17 +1111,21 @@ impl<'a, E> de::VariantVisitor for VariantRefDeserializer<'a, E> where E: de::Er
|
||||
de::Deserializer::deserialize(MapRefDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"struct variant")),
|
||||
_ => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"struct variant"))
|
||||
_ => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"struct variant")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SeqRefDeserializer<'a, E> where E: de::Error {
|
||||
struct SeqRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
iter: <&'a [Content] as IntoIterator>::IntoIter,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, E> SeqRefDeserializer<'a, E> where E: de::Error {
|
||||
impl<'a, E> SeqRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
fn new(vec: &'a [Content]) -> Self {
|
||||
SeqRefDeserializer {
|
||||
iter: vec.into_iter(),
|
||||
@ -1085,12 +1134,14 @@ impl<'a, E> SeqRefDeserializer<'a, E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::Deserializer for SeqRefDeserializer<'a, E> where E: de::Error {
|
||||
impl<'a, E> de::Deserializer 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
|
||||
{
|
||||
let len = self.iter.len();
|
||||
if len == 0 {
|
||||
@ -1113,11 +1164,13 @@ impl<'a, E> de::Deserializer for SeqRefDeserializer<'a, E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::SeqVisitor for SeqRefDeserializer<'a, E> where E: de::Error {
|
||||
impl<'a, E> de::SeqVisitor 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
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)).map(Some),
|
||||
@ -1130,13 +1183,17 @@ impl<'a, E> de::SeqVisitor for SeqRefDeserializer<'a, E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
struct MapRefDeserializer<'a, E> where E: de::Error {
|
||||
struct MapRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
iter: <&'a [(Content, Content)] as IntoIterator>::IntoIter,
|
||||
value: Option<&'a Content>,
|
||||
err: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<'a, E> MapRefDeserializer<'a, E> where E: de::Error {
|
||||
impl<'a, E> MapRefDeserializer<'a, E>
|
||||
where E: de::Error
|
||||
{
|
||||
fn new(map: &'a [(Content, Content)]) -> Self {
|
||||
MapRefDeserializer {
|
||||
iter: map.into_iter(),
|
||||
@ -1146,11 +1203,13 @@ impl<'a, E> MapRefDeserializer<'a, E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::MapVisitor for MapRefDeserializer<'a, E> where E: de::Error {
|
||||
impl<'a, E> de::MapVisitor 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
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(&(ref key, ref value)) => {
|
||||
@ -1162,7 +1221,7 @@ impl<'a, E> de::MapVisitor for MapRefDeserializer<'a, E> where E: de::Error {
|
||||
}
|
||||
|
||||
fn visit_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
|
||||
where T: de::DeserializeSeed,
|
||||
where T: de::DeserializeSeed
|
||||
{
|
||||
match self.value.take() {
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)),
|
||||
@ -1175,12 +1234,14 @@ impl<'a, E> de::MapVisitor for MapRefDeserializer<'a, E> where E: de::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> de::Deserializer for MapRefDeserializer<'a, E> where E: de::Error {
|
||||
impl<'a, E> de::Deserializer 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
|
||||
{
|
||||
visitor.visit_map(self)
|
||||
}
|
||||
|
@ -182,9 +182,9 @@ pub trait Error: Sized + error::Error {
|
||||
}
|
||||
}
|
||||
Error::custom(InvalidType {
|
||||
unexp: unexp,
|
||||
exp: exp,
|
||||
})
|
||||
unexp: unexp,
|
||||
exp: exp,
|
||||
})
|
||||
}
|
||||
|
||||
/// Raised when a `Deserialize` receives a value of the right type but that
|
||||
@ -211,9 +211,9 @@ pub trait Error: Sized + error::Error {
|
||||
}
|
||||
}
|
||||
Error::custom(InvalidValue {
|
||||
unexp: unexp,
|
||||
exp: exp,
|
||||
})
|
||||
unexp: unexp,
|
||||
exp: exp,
|
||||
})
|
||||
}
|
||||
|
||||
/// Raised when deserializing a sequence or map and the input data contains
|
||||
@ -236,9 +236,9 @@ pub trait Error: Sized + error::Error {
|
||||
}
|
||||
}
|
||||
Error::custom(InvalidLength {
|
||||
len: len,
|
||||
exp: exp,
|
||||
})
|
||||
len: len,
|
||||
exp: exp,
|
||||
})
|
||||
}
|
||||
|
||||
/// Raised when a `Deserialize` enum type received a variant with an
|
||||
@ -263,9 +263,9 @@ pub trait Error: Sized + error::Error {
|
||||
}
|
||||
}
|
||||
Error::custom(UnknownVariant {
|
||||
variant: variant,
|
||||
expected: expected,
|
||||
})
|
||||
variant: variant,
|
||||
expected: expected,
|
||||
})
|
||||
}
|
||||
|
||||
/// Raised when a `Deserialize` struct type received a field with an
|
||||
@ -290,9 +290,9 @@ pub trait Error: Sized + error::Error {
|
||||
}
|
||||
}
|
||||
Error::custom(UnknownField {
|
||||
field: field,
|
||||
expected: expected,
|
||||
})
|
||||
field: field,
|
||||
expected: expected,
|
||||
})
|
||||
}
|
||||
|
||||
/// Raised when a `Deserialize` struct type expected to receive a required
|
||||
|
@ -192,11 +192,11 @@ primitive_deserializer!(char, CharDeserializer, visit_char);
|
||||
/// A helper deserializer that deserializes a number.
|
||||
pub struct U32Deserializer<E> {
|
||||
value: u32,
|
||||
marker: PhantomData<E>
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<E> ValueDeserializer<E> for u32
|
||||
where E: de::Error,
|
||||
where E: de::Error
|
||||
{
|
||||
type Deserializer = U32Deserializer<E>;
|
||||
|
||||
@ -209,7 +209,7 @@ impl<E> ValueDeserializer<E> for u32
|
||||
}
|
||||
|
||||
impl<E> de::Deserializer for U32Deserializer<E>
|
||||
where E: de::Error,
|
||||
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
|
||||
{
|
||||
visitor.visit_u32(self.value)
|
||||
}
|
||||
|
@ -33,10 +33,7 @@ impl<M> ser::SerializeTupleVariant for SerializeTupleVariantAsMapValue<M>
|
||||
type Ok = M::Ok;
|
||||
type Error = M::Error;
|
||||
|
||||
fn serialize_field<T: ?Sized + Serialize>(&mut self,
|
||||
value: &T)
|
||||
-> Result<(), M::Error>
|
||||
{
|
||||
fn serialize_field<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), M::Error> {
|
||||
let value = try!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||
self.fields.push(value);
|
||||
Ok(())
|
||||
@ -73,8 +70,7 @@ impl<M> ser::SerializeStructVariant for SerializeStructVariantAsMapValue<M>
|
||||
fn serialize_field<T: ?Sized + Serialize>(&mut self,
|
||||
key: &'static str,
|
||||
value: &T)
|
||||
-> Result<(), M::Error>
|
||||
{
|
||||
-> Result<(), M::Error> {
|
||||
let value = try!(value.serialize(ContentSerializer::<M::Error>::new()));
|
||||
self.fields.push((key, value));
|
||||
Ok(())
|
||||
@ -151,7 +147,9 @@ impl Serialize for Content {
|
||||
Content::UnitStruct(n) => serializer.serialize_unit_struct(n),
|
||||
Content::UnitVariant(n, i, v) => serializer.serialize_unit_variant(n, i, v),
|
||||
Content::NewtypeStruct(n, ref c) => serializer.serialize_newtype_struct(n, &**c),
|
||||
Content::NewtypeVariant(n, i, v, ref c) => serializer.serialize_newtype_variant(n, i, v, &**c),
|
||||
Content::NewtypeVariant(n, i, v, ref c) => {
|
||||
serializer.serialize_newtype_variant(n, i, v, &**c)
|
||||
}
|
||||
Content::Seq(ref elements) => elements.serialize(serializer),
|
||||
Content::SeqFixedSize(ref elements) => {
|
||||
use ser::SerializeSeq;
|
||||
@ -219,9 +217,7 @@ struct ContentSerializer<E> {
|
||||
|
||||
impl<E> ContentSerializer<E> {
|
||||
fn new() -> Self {
|
||||
ContentSerializer {
|
||||
error: PhantomData,
|
||||
}
|
||||
ContentSerializer { error: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,9 +295,7 @@ impl<E> Serializer for ContentSerializer<E>
|
||||
Ok(Content::None)
|
||||
}
|
||||
|
||||
fn serialize_some<T: ?Sized + Serialize>(self,
|
||||
value: &T)
|
||||
-> Result<Content, E> {
|
||||
fn serialize_some<T: ?Sized + Serialize>(self, value: &T) -> Result<Content, E> {
|
||||
Ok(Content::Some(Box::new(try!(value.serialize(self)))))
|
||||
}
|
||||
|
||||
@ -309,9 +303,7 @@ impl<E> Serializer for ContentSerializer<E>
|
||||
Ok(Content::Unit)
|
||||
}
|
||||
|
||||
fn serialize_unit_struct(self,
|
||||
name: &'static str)
|
||||
-> Result<Content, E> {
|
||||
fn serialize_unit_struct(self, name: &'static str) -> Result<Content, E> {
|
||||
Ok(Content::UnitStruct(name))
|
||||
}
|
||||
|
||||
@ -336,36 +328,33 @@ impl<E> Serializer for ContentSerializer<E>
|
||||
variant: &'static str,
|
||||
value: &T)
|
||||
-> Result<Content, E> {
|
||||
Ok(Content::NewtypeVariant(name, variant_index, variant, Box::new(try!(value.serialize(self)))))
|
||||
Ok(Content::NewtypeVariant(name,
|
||||
variant_index,
|
||||
variant,
|
||||
Box::new(try!(value.serialize(self)))))
|
||||
}
|
||||
|
||||
fn serialize_seq(self,
|
||||
len: Option<usize>)
|
||||
-> Result<Self::SerializeSeq, E> {
|
||||
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, E> {
|
||||
Ok(SerializeSeq {
|
||||
fixed_size: false,
|
||||
elements: Vec::with_capacity(len.unwrap_or(0)),
|
||||
error: PhantomData,
|
||||
})
|
||||
fixed_size: false,
|
||||
elements: Vec::with_capacity(len.unwrap_or(0)),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_seq_fixed_size(self,
|
||||
size: usize)
|
||||
-> Result<Self::SerializeSeq, E> {
|
||||
fn serialize_seq_fixed_size(self, size: usize) -> Result<Self::SerializeSeq, E> {
|
||||
Ok(SerializeSeq {
|
||||
fixed_size: true,
|
||||
elements: Vec::with_capacity(size),
|
||||
error: PhantomData,
|
||||
})
|
||||
fixed_size: true,
|
||||
elements: Vec::with_capacity(size),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_tuple(self,
|
||||
len: usize)
|
||||
-> Result<Self::SerializeTuple, E> {
|
||||
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, E> {
|
||||
Ok(SerializeTuple {
|
||||
elements: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
elements: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct(self,
|
||||
@ -373,10 +362,10 @@ impl<E> Serializer for ContentSerializer<E>
|
||||
len: usize)
|
||||
-> Result<Self::SerializeTupleStruct, E> {
|
||||
Ok(SerializeTupleStruct {
|
||||
name: name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
name: name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant(self,
|
||||
@ -386,33 +375,28 @@ impl<E> Serializer for ContentSerializer<E>
|
||||
len: usize)
|
||||
-> Result<Self::SerializeTupleVariant, E> {
|
||||
Ok(SerializeTupleVariant {
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_map(self,
|
||||
len: Option<usize>)
|
||||
-> Result<Self::SerializeMap, E> {
|
||||
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, E> {
|
||||
Ok(SerializeMap {
|
||||
entries: Vec::with_capacity(len.unwrap_or(0)),
|
||||
key: None,
|
||||
error: PhantomData,
|
||||
})
|
||||
entries: Vec::with_capacity(len.unwrap_or(0)),
|
||||
key: None,
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_struct(self,
|
||||
name: &'static str,
|
||||
len: usize)
|
||||
-> Result<Self::SerializeStruct, E> {
|
||||
fn serialize_struct(self, name: &'static str, len: usize) -> Result<Self::SerializeStruct, E> {
|
||||
Ok(SerializeStruct {
|
||||
name: name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
name: name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_struct_variant(self,
|
||||
@ -422,12 +406,12 @@ impl<E> Serializer for ContentSerializer<E>
|
||||
len: usize)
|
||||
-> Result<Self::SerializeStructVariant, E> {
|
||||
Ok(SerializeStructVariant {
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -443,9 +427,7 @@ impl<E> ser::SerializeSeq for SerializeSeq<E>
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_element<T: ?Sized + Serialize>(&mut self,
|
||||
value: &T)
|
||||
-> Result<(), E> {
|
||||
fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), E> {
|
||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.elements.push(value);
|
||||
Ok(())
|
||||
@ -453,10 +435,10 @@ impl<E> ser::SerializeSeq for SerializeSeq<E>
|
||||
|
||||
fn end(self) -> Result<Content, E> {
|
||||
Ok(if self.fixed_size {
|
||||
Content::SeqFixedSize(self.elements)
|
||||
} else {
|
||||
Content::Seq(self.elements)
|
||||
})
|
||||
Content::SeqFixedSize(self.elements)
|
||||
} else {
|
||||
Content::Seq(self.elements)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,9 +453,7 @@ impl<E> ser::SerializeTuple for SerializeTuple<E>
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_element<T: ?Sized + Serialize>(&mut self,
|
||||
value: &T)
|
||||
-> Result<(), E> {
|
||||
fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), E> {
|
||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.elements.push(value);
|
||||
Ok(())
|
||||
@ -496,9 +476,7 @@ impl<E> ser::SerializeTupleStruct for SerializeTupleStruct<E>
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_field<T: ?Sized + Serialize>(&mut self,
|
||||
value: &T)
|
||||
-> Result<(), E> {
|
||||
fn serialize_field<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), E> {
|
||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.fields.push(value);
|
||||
Ok(())
|
||||
@ -523,9 +501,7 @@ impl<E> ser::SerializeTupleVariant for SerializeTupleVariant<E>
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_field<T: ?Sized + Serialize>(&mut self,
|
||||
value: &T)
|
||||
-> Result<(), E> {
|
||||
fn serialize_field<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), E> {
|
||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.fields.push(value);
|
||||
Ok(())
|
||||
@ -548,17 +524,13 @@ impl<E> ser::SerializeMap for SerializeMap<E>
|
||||
type Ok = Content;
|
||||
type Error = E;
|
||||
|
||||
fn serialize_key<T: ?Sized + Serialize>(&mut self,
|
||||
key: &T)
|
||||
-> Result<(), E> {
|
||||
fn serialize_key<T: ?Sized + Serialize>(&mut self, key: &T) -> Result<(), E> {
|
||||
let key = try!(key.serialize(ContentSerializer::<E>::new()));
|
||||
self.key = Some(key);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_value<T: ?Sized + Serialize>(&mut self,
|
||||
value: &T)
|
||||
-> Result<(), E> {
|
||||
fn serialize_value<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), E> {
|
||||
let key = self.key.take().expect("serialize_value called before serialize_key");
|
||||
let value = try!(value.serialize(ContentSerializer::<E>::new()));
|
||||
self.entries.push((key, value));
|
||||
|
@ -646,7 +646,7 @@ pub trait Serializer: Sized {
|
||||
/// ```
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where T: Display,
|
||||
where T: Display
|
||||
{
|
||||
let mut string = String::new();
|
||||
write!(string, "{}", value).unwrap();
|
||||
@ -677,7 +677,7 @@ pub trait Serializer: Sized {
|
||||
/// ```
|
||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
||||
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where T: Display,
|
||||
where T: Display
|
||||
{
|
||||
// TODO https://github.com/serde-rs/serde/issues/805
|
||||
// Remove this impl and force no_std formats to implement collect_str.
|
||||
|
@ -17,12 +17,12 @@ pub fn serialize_tagged_newtype<S, T>(serializer: S,
|
||||
T: Serialize
|
||||
{
|
||||
value.serialize(TaggedSerializer {
|
||||
type_ident: type_ident,
|
||||
variant_ident: variant_ident,
|
||||
tag: tag,
|
||||
variant_name: variant_name,
|
||||
delegate: serializer,
|
||||
})
|
||||
type_ident: type_ident,
|
||||
variant_ident: variant_ident,
|
||||
tag: tag,
|
||||
variant_name: variant_name,
|
||||
delegate: serializer,
|
||||
})
|
||||
}
|
||||
|
||||
struct TaggedSerializer<S> {
|
||||
@ -81,7 +81,9 @@ impl Display for Error {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter,
|
||||
"cannot serialize tagged newtype variant {}::{} containing {}",
|
||||
self.type_ident, self.variant_ident, self.ty)
|
||||
self.type_ident,
|
||||
self.variant_ident,
|
||||
self.ty)
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,10 +92,10 @@ impl<S> TaggedSerializer<S>
|
||||
{
|
||||
fn bad_type(self, what: Unsupported) -> S::Error {
|
||||
ser::Error::custom(Error {
|
||||
type_ident: self.type_ident,
|
||||
variant_ident: self.variant_ident,
|
||||
ty: what,
|
||||
})
|
||||
type_ident: self.type_ident,
|
||||
variant_ident: self.variant_ident,
|
||||
ty: what,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,8 @@ const Pattern_White_Space_table: &'static [(char, char)] = &[('\u{9}', '\u{d}'),
|
||||
fn bsearch_range_table(c: char, r: &'static [(char, char)]) -> bool {
|
||||
use core::cmp::Ordering::{Equal, Less, Greater};
|
||||
r.binary_search_by(|&(lo, hi)| if c < lo {
|
||||
Greater
|
||||
} else if hi < c {
|
||||
Greater
|
||||
} else if hi < c {
|
||||
Less
|
||||
} else {
|
||||
Equal
|
||||
|
Loading…
x
Reference in New Issue
Block a user