mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 08:07:56 +00:00
Format with rustfmt-nightly 0.3.4
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
use lib::*;
|
||||
|
||||
use de::{Deserialize, Deserializer, Visitor, SeqAccess, MapAccess, Error};
|
||||
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||
|
||||
/// An efficient way of discarding data from a deserializer.
|
||||
///
|
||||
|
||||
+60
-30
@@ -52,7 +52,6 @@ impl<'de> Deserialize<'de> for () {
|
||||
|
||||
struct BoolVisitor;
|
||||
|
||||
|
||||
impl<'de> Visitor<'de> for BoolVisitor {
|
||||
type Value = bool;
|
||||
|
||||
@@ -253,7 +252,10 @@ impl<'de> Visitor<'de> for StringVisitor {
|
||||
{
|
||||
match String::from_utf8(v) {
|
||||
Ok(s) => Ok(s),
|
||||
Err(e) => Err(Error::invalid_value(Unexpected::Bytes(&e.into_bytes()), &self),),
|
||||
Err(e) => Err(Error::invalid_value(
|
||||
Unexpected::Bytes(&e.into_bytes()),
|
||||
&self,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,7 +308,10 @@ impl<'a, 'de> Visitor<'de> for StringInPlaceVisitor<'a> {
|
||||
*self.0 = s;
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => Err(Error::invalid_value(Unexpected::Bytes(&e.into_bytes()), &self),),
|
||||
Err(e) => Err(Error::invalid_value(
|
||||
Unexpected::Bytes(&e.into_bytes()),
|
||||
&self,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -529,7 +534,9 @@ where
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_option(OptionVisitor { marker: PhantomData })
|
||||
deserializer.deserialize_option(OptionVisitor {
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
// The Some variant's repr is opaque, so we can't play cute tricks with its
|
||||
@@ -566,7 +573,9 @@ impl<'de, T> Deserialize<'de> for PhantomData<T> {
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let visitor = PhantomDataVisitor { marker: PhantomData };
|
||||
let visitor = PhantomDataVisitor {
|
||||
marker: PhantomData,
|
||||
};
|
||||
deserializer.deserialize_unit_struct("PhantomData", visitor)
|
||||
}
|
||||
}
|
||||
@@ -699,7 +708,8 @@ seq_impl!(
|
||||
LinkedList::clear,
|
||||
LinkedList::new(),
|
||||
nop_reserve,
|
||||
LinkedList::push_back);
|
||||
LinkedList::push_back
|
||||
);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
seq_impl!(
|
||||
@@ -719,7 +729,8 @@ seq_impl!(
|
||||
Vec::clear,
|
||||
Vec::with_capacity(size_hint::cautious(seq.size_hint())),
|
||||
Vec::reserve,
|
||||
Vec::push);
|
||||
Vec::push
|
||||
);
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
seq_impl!(
|
||||
@@ -729,7 +740,8 @@ seq_impl!(
|
||||
VecDeque::clear,
|
||||
VecDeque::with_capacity(size_hint::cautious(seq.size_hint())),
|
||||
VecDeque::reserve,
|
||||
VecDeque::push_back);
|
||||
VecDeque::push_back
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -740,7 +752,9 @@ struct ArrayInPlaceVisitor<'a, A: 'a>(&'a mut A);
|
||||
|
||||
impl<A> ArrayVisitor<A> {
|
||||
fn new() -> Self {
|
||||
ArrayVisitor { marker: PhantomData }
|
||||
ArrayVisitor {
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1257,7 +1271,12 @@ impl<'de> Deserialize<'de> for net::SocketAddr {
|
||||
parse_socket_impl!(net::SocketAddrV4, net::SocketAddrV4::new);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
parse_socket_impl!(net::SocketAddrV6, |ip, port| net::SocketAddrV6::new(ip, port, 0, 0));
|
||||
parse_socket_impl!(net::SocketAddrV6, |ip, port| net::SocketAddrV6::new(
|
||||
ip,
|
||||
port,
|
||||
0,
|
||||
0
|
||||
));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1368,7 +1387,9 @@ impl<'de> Visitor<'de> for OsStringVisitor {
|
||||
|
||||
match try!(data.variant()) {
|
||||
(OsStringKind::Unix, v) => v.newtype_variant().map(OsString::from_vec),
|
||||
(OsStringKind::Windows, _) => Err(Error::custom("cannot deserialize Windows OS string on Unix",),),
|
||||
(OsStringKind::Windows, _) => Err(Error::custom(
|
||||
"cannot deserialize Windows OS string on Unix",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1380,11 +1401,11 @@ impl<'de> Visitor<'de> for OsStringVisitor {
|
||||
use std::os::windows::ffi::OsStringExt;
|
||||
|
||||
match try!(data.variant()) {
|
||||
(OsStringKind::Windows, v) => {
|
||||
v.newtype_variant::<Vec<u16>>()
|
||||
.map(|vec| OsString::from_wide(&vec))
|
||||
}
|
||||
(OsStringKind::Unix, _) => Err(Error::custom("cannot deserialize Unix OS string on Windows",),),
|
||||
(OsStringKind::Windows, v) => v.newtype_variant::<Vec<u16>>()
|
||||
.map(|vec| OsString::from_wide(&vec)),
|
||||
(OsStringKind::Unix, _) => Err(Error::custom(
|
||||
"cannot deserialize Unix OS string on Windows",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1710,13 +1731,17 @@ impl<'de> Deserialize<'de> for SystemTime {
|
||||
match key {
|
||||
Field::Secs => {
|
||||
if secs.is_some() {
|
||||
return Err(<A::Error as Error>::duplicate_field("secs_since_epoch"));
|
||||
return Err(<A::Error as Error>::duplicate_field(
|
||||
"secs_since_epoch",
|
||||
));
|
||||
}
|
||||
secs = Some(try!(map.next_value()));
|
||||
}
|
||||
Field::Nanos => {
|
||||
if nanos.is_some() {
|
||||
return Err(<A::Error as Error>::duplicate_field("nanos_since_epoch"));
|
||||
return Err(<A::Error as Error>::duplicate_field(
|
||||
"nanos_since_epoch",
|
||||
));
|
||||
}
|
||||
nanos = Some(try!(map.next_value()));
|
||||
}
|
||||
@@ -1880,7 +1905,13 @@ where
|
||||
}
|
||||
|
||||
const FIELDS: &'static [&'static str] = &["start", "end"];
|
||||
deserializer.deserialize_struct("Range", FIELDS, RangeVisitor { phantom: PhantomData })
|
||||
deserializer.deserialize_struct(
|
||||
"Range",
|
||||
FIELDS,
|
||||
RangeVisitor {
|
||||
phantom: PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1945,9 +1976,10 @@ where
|
||||
match value {
|
||||
0 => Ok(Field::Ok),
|
||||
1 => Ok(Field::Err),
|
||||
_ => {
|
||||
Err(Error::invalid_value(Unexpected::Unsigned(value as u64), &self),)
|
||||
}
|
||||
_ => Err(Error::invalid_value(
|
||||
Unexpected::Unsigned(value as u64),
|
||||
&self,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1969,14 +2001,12 @@ where
|
||||
match value {
|
||||
b"Ok" => Ok(Field::Ok),
|
||||
b"Err" => Ok(Field::Err),
|
||||
_ => {
|
||||
match str::from_utf8(value) {
|
||||
Ok(value) => Err(Error::unknown_variant(value, VARIANTS)),
|
||||
Err(_) => {
|
||||
Err(Error::invalid_value(Unexpected::Bytes(value), &self))
|
||||
}
|
||||
_ => match str::from_utf8(value) {
|
||||
Ok(value) => Err(Error::unknown_variant(value, VARIANTS)),
|
||||
Err(_) => {
|
||||
Err(Error::invalid_value(Unexpected::Bytes(value), &self))
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2020,7 +2050,7 @@ where
|
||||
#[cfg(feature = "std")]
|
||||
impl<'de, T> Deserialize<'de> for Wrapping<T>
|
||||
where
|
||||
T: Deserialize<'de>
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<Wrapping<T>, D::Error>
|
||||
where
|
||||
|
||||
+5
-2
@@ -526,7 +526,8 @@ pub trait Deserialize<'de>: Sized {
|
||||
/// than it deserves.
|
||||
#[doc(hidden)]
|
||||
fn deserialize_in_place<D>(deserializer: D, place: &mut Self) -> Result<(), D::Error>
|
||||
where D: Deserializer<'de>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
// Default implementation just delegates to `deserialize` impl.
|
||||
*place = Deserialize::deserialize(deserializer)?;
|
||||
@@ -1106,7 +1107,9 @@ pub trait Deserializer<'de>: Sized {
|
||||
/// change, as a value serialized in human-readable mode is not required to
|
||||
/// deserialize from the same data in compact mode.
|
||||
#[inline]
|
||||
fn is_human_readable(&self) -> bool { true }
|
||||
fn is_human_readable(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+34
-14
@@ -37,7 +37,7 @@
|
||||
|
||||
use lib::*;
|
||||
|
||||
use de::{self, IntoDeserializer, Expected, SeqAccess};
|
||||
use de::{self, Expected, IntoDeserializer, SeqAccess};
|
||||
use private::de::size_hint;
|
||||
use ser;
|
||||
use self::private::{First, Second};
|
||||
@@ -62,7 +62,9 @@ impl de::Error for Error {
|
||||
where
|
||||
T: Display,
|
||||
{
|
||||
Error { err: msg.to_string().into_boxed_str() }
|
||||
Error {
|
||||
err: msg.to_string().into_boxed_str(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "std", feature = "alloc")))]
|
||||
@@ -112,7 +114,9 @@ where
|
||||
type Deserializer = UnitDeserializer<E>;
|
||||
|
||||
fn into_deserializer(self) -> UnitDeserializer<E> {
|
||||
UnitDeserializer { marker: PhantomData }
|
||||
UnitDeserializer {
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,7 +662,10 @@ where
|
||||
} else {
|
||||
// First argument is the number of elements in the data, second
|
||||
// argument is the number of elements expected by the Deserialize.
|
||||
Err(de::Error::invalid_length(self.count + remaining, &ExpectedInSeq(self.count)),)
|
||||
Err(de::Error::invalid_length(
|
||||
self.count + remaining,
|
||||
&ExpectedInSeq(self.count),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -852,7 +859,10 @@ where
|
||||
} else {
|
||||
// First argument is the number of elements in the data, second
|
||||
// argument is the number of elements expected by the Deserialize.
|
||||
Err(de::Error::invalid_length(self.count + remaining, &ExpectedInMap(self.count)),)
|
||||
Err(de::Error::invalid_length(
|
||||
self.count + remaining,
|
||||
&ExpectedInMap(self.count),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -901,11 +911,7 @@ where
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn deserialize_tuple<V>(
|
||||
self,
|
||||
len: usize,
|
||||
visitor: V,
|
||||
) -> Result<V::Value, Self::Error>
|
||||
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: de::Visitor<'de>,
|
||||
{
|
||||
@@ -1223,7 +1229,12 @@ mod private {
|
||||
}
|
||||
|
||||
pub fn unit_only<T, E>(t: T) -> (T, UnitOnly<E>) {
|
||||
(t, UnitOnly { marker: PhantomData })
|
||||
(
|
||||
t,
|
||||
UnitOnly {
|
||||
marker: PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
impl<'de, E> de::VariantAccess<'de> for UnitOnly<E>
|
||||
@@ -1240,14 +1251,20 @@ mod private {
|
||||
where
|
||||
T: de::DeserializeSeed<'de>,
|
||||
{
|
||||
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"newtype variant"),)
|
||||
Err(de::Error::invalid_type(
|
||||
Unexpected::UnitVariant,
|
||||
&"newtype variant",
|
||||
))
|
||||
}
|
||||
|
||||
fn tuple_variant<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: de::Visitor<'de>,
|
||||
{
|
||||
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"tuple variant"),)
|
||||
Err(de::Error::invalid_type(
|
||||
Unexpected::UnitVariant,
|
||||
&"tuple variant",
|
||||
))
|
||||
}
|
||||
|
||||
fn struct_variant<V>(
|
||||
@@ -1258,7 +1275,10 @@ mod private {
|
||||
where
|
||||
V: de::Visitor<'de>,
|
||||
{
|
||||
Err(de::Error::invalid_type(Unexpected::UnitVariant, &"struct variant"),)
|
||||
Err(de::Error::invalid_type(
|
||||
Unexpected::UnitVariant,
|
||||
&"struct variant",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ pub use lib::default::Default;
|
||||
pub use lib::fmt::{self, Formatter};
|
||||
pub use lib::marker::PhantomData;
|
||||
pub use lib::option::Option::{self, None, Some};
|
||||
pub use lib::result::Result::{self, Ok, Err};
|
||||
pub use lib::result::Result::{self, Err, Ok};
|
||||
|
||||
pub use self::string::from_utf8_lossy;
|
||||
|
||||
|
||||
+10
-20
@@ -80,29 +80,20 @@
|
||||
|
||||
// Serde types in rustdoc of other crates get linked to here.
|
||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.24")]
|
||||
|
||||
// Support using Serde without the standard library!
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
// Unstable functionality only if the user asks for it. For tracking and
|
||||
// discussion of these features please refer to this issue:
|
||||
//
|
||||
// https://github.com/serde-rs/serde/issues/812
|
||||
#![cfg_attr(feature = "unstable", feature(nonzero, specialization))]
|
||||
#![cfg_attr(feature = "alloc", feature(alloc))]
|
||||
|
||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||
// Whitelisted clippy lints
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(
|
||||
cast_lossless,
|
||||
const_static_lifetime,
|
||||
doc_markdown,
|
||||
linkedlist,
|
||||
needless_pass_by_value,
|
||||
type_complexity,
|
||||
unreadable_literal,
|
||||
zero_prefixed_literal,
|
||||
))]
|
||||
#![cfg_attr(feature = "cargo-clippy",
|
||||
allow(cast_lossless, const_static_lifetime, doc_markdown, linkedlist,
|
||||
needless_pass_by_value, type_complexity, unreadable_literal,
|
||||
zero_prefixed_literal))]
|
||||
// Whitelisted clippy_pedantic lints
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(
|
||||
// integer and float ser/de requires these sorts of casts
|
||||
@@ -125,7 +116,6 @@
|
||||
empty_enum,
|
||||
use_debug,
|
||||
))]
|
||||
|
||||
// Blacklisted Rust lints.
|
||||
#![deny(missing_docs, unused_imports)]
|
||||
|
||||
@@ -149,8 +139,8 @@ mod lib {
|
||||
}
|
||||
|
||||
pub use self::core::{cmp, iter, mem, ops, slice, str};
|
||||
pub use self::core::{i8, i16, i32, i64, isize};
|
||||
pub use self::core::{u8, u16, u32, u64, usize};
|
||||
pub use self::core::{isize, i16, i32, i64, i8};
|
||||
pub use self::core::{usize, u16, u32, u64, u8};
|
||||
pub use self::core::{f32, f64};
|
||||
|
||||
pub use self::core::cell::{Cell, RefCell};
|
||||
@@ -193,9 +183,9 @@ mod lib {
|
||||
pub use alloc::arc::Arc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::collections::{BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque};
|
||||
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
pub use alloc::{BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque};
|
||||
pub use alloc::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::{error, net};
|
||||
@@ -203,9 +193,9 @@ mod lib {
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::collections::{HashMap, HashSet};
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::ffi::{CString, CStr, OsString, OsStr};
|
||||
pub use std::ffi::{CStr, CString, OsStr, OsString};
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::hash::{Hash, BuildHasher};
|
||||
pub use std::hash::{BuildHasher, Hash};
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::io::Write;
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
+139
-103
@@ -8,16 +8,16 @@
|
||||
|
||||
use lib::*;
|
||||
|
||||
use de::{Deserialize, Deserializer, DeserializeSeed, IntoDeserializer, Error, Visitor};
|
||||
use de::{Deserialize, DeserializeSeed, Deserializer, Error, IntoDeserializer, Visitor};
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
use de::Unexpected;
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
pub use self::content::{Content, ContentRefDeserializer, ContentDeserializer,
|
||||
TaggedContentVisitor, TagOrContentField, TagOrContentFieldVisitor,
|
||||
TagContentOtherField, TagContentOtherFieldVisitor,
|
||||
InternallyTaggedUnitVisitor, UntaggedUnitVisitor};
|
||||
pub use self::content::{Content, ContentDeserializer, ContentRefDeserializer,
|
||||
InternallyTaggedUnitVisitor, TagContentOtherField,
|
||||
TagContentOtherFieldVisitor, TagOrContentField, TagOrContentFieldVisitor,
|
||||
TaggedContentVisitor, UntaggedUnitVisitor};
|
||||
|
||||
/// If the missing field is of type `Option<T>` then treat is as `None`,
|
||||
/// otherwise it is an error.
|
||||
@@ -120,7 +120,10 @@ where
|
||||
{
|
||||
match String::from_utf8(v) {
|
||||
Ok(s) => Ok(Cow::Owned(s)),
|
||||
Err(e) => Err(Error::invalid_value(Unexpected::Bytes(&e.into_bytes()), &self),),
|
||||
Err(e) => Err(Error::invalid_value(
|
||||
Unexpected::Bytes(&e.into_bytes()),
|
||||
&self,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,8 +228,8 @@ mod content {
|
||||
|
||||
use lib::*;
|
||||
|
||||
use de::{self, Deserialize, DeserializeSeed, Deserializer, Visitor, SeqAccess, MapAccess,
|
||||
EnumAccess, Unexpected};
|
||||
use de::{self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, MapAccess, SeqAccess,
|
||||
Unexpected, Visitor};
|
||||
use super::size_hint;
|
||||
|
||||
/// Used from generated code to buffer the contents of the Deserializer when
|
||||
@@ -502,7 +505,9 @@ mod content {
|
||||
where
|
||||
V: EnumAccess<'de>,
|
||||
{
|
||||
Err(de::Error::custom("untagged and internally tagged enums do not support enum input",),)
|
||||
Err(de::Error::custom(
|
||||
"untagged and internally tagged enums do not support enum input",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,7 +526,10 @@ mod content {
|
||||
|
||||
impl<'de> TagOrContentVisitor<'de> {
|
||||
fn new(name: &'static str) -> Self {
|
||||
TagOrContentVisitor { name: name, value: PhantomData }
|
||||
TagOrContentVisitor {
|
||||
name: name,
|
||||
value: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,7 +566,9 @@ mod content {
|
||||
where
|
||||
F: de::Error,
|
||||
{
|
||||
ContentVisitor::new().visit_i8(value).map(TagOrContent::Content)
|
||||
ContentVisitor::new()
|
||||
.visit_i8(value)
|
||||
.map(TagOrContent::Content)
|
||||
}
|
||||
|
||||
fn visit_i16<F>(self, value: i16) -> Result<Self::Value, F>
|
||||
@@ -592,7 +602,9 @@ mod content {
|
||||
where
|
||||
F: de::Error,
|
||||
{
|
||||
ContentVisitor::new().visit_u8(value).map(TagOrContent::Content)
|
||||
ContentVisitor::new()
|
||||
.visit_u8(value)
|
||||
.map(TagOrContent::Content)
|
||||
}
|
||||
|
||||
fn visit_u16<F>(self, value: u16) -> Result<Self::Value, F>
|
||||
@@ -731,14 +743,18 @@ mod content {
|
||||
where
|
||||
F: de::Error,
|
||||
{
|
||||
ContentVisitor::new().visit_unit().map(TagOrContent::Content)
|
||||
ContentVisitor::new()
|
||||
.visit_unit()
|
||||
.map(TagOrContent::Content)
|
||||
}
|
||||
|
||||
fn visit_none<F>(self) -> Result<Self::Value, F>
|
||||
where
|
||||
F: de::Error,
|
||||
{
|
||||
ContentVisitor::new().visit_none().map(TagOrContent::Content)
|
||||
ContentVisitor::new()
|
||||
.visit_none()
|
||||
.map(TagOrContent::Content)
|
||||
}
|
||||
|
||||
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
@@ -861,8 +877,7 @@ mod content {
|
||||
{
|
||||
let mut tag = None;
|
||||
let mut vec = Vec::with_capacity(size_hint::cautious(map.size_hint()));
|
||||
while let Some(k) =
|
||||
try!(map.next_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
||||
while let Some(k) = try!(map.next_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
||||
match k {
|
||||
TagOrContent::Tag => {
|
||||
if tag.is_some() {
|
||||
@@ -878,14 +893,10 @@ mod content {
|
||||
}
|
||||
match tag {
|
||||
None => Err(de::Error::missing_field(self.tag_name)),
|
||||
Some(tag) => {
|
||||
Ok(
|
||||
TaggedContent {
|
||||
tag: tag,
|
||||
content: Content::Map(vec),
|
||||
},
|
||||
)
|
||||
}
|
||||
Some(tag) => Ok(TaggedContent {
|
||||
tag: tag,
|
||||
content: Content::Map(vec),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -967,7 +978,11 @@ mod content {
|
||||
type Value = TagContentOtherField;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "{:?}, {:?}, or other ignored fields", self.tag, self.content)
|
||||
write!(
|
||||
formatter,
|
||||
"{:?}, {:?}, or other ignored fields",
|
||||
self.tag, self.content
|
||||
)
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, field: &str) -> Result<Self::Value, E>
|
||||
@@ -1031,10 +1046,8 @@ mod content {
|
||||
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());
|
||||
@@ -1081,44 +1094,41 @@ mod content {
|
||||
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))
|
||||
}
|
||||
s @ Content::String(_) | s @ Content::Str(_) => (s, None),
|
||||
other => {
|
||||
return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),);
|
||||
return Err(de::Error::invalid_type(
|
||||
other.unexpected(),
|
||||
&"string or map",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
visitor.visit_enum(
|
||||
EnumDeserializer {
|
||||
variant: variant,
|
||||
value: value,
|
||||
err: PhantomData,
|
||||
},
|
||||
)
|
||||
visitor.visit_enum(EnumDeserializer {
|
||||
variant: variant,
|
||||
value: value,
|
||||
err: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn deserialize_unit_struct<V>(
|
||||
self,
|
||||
_name: &'static str,
|
||||
visitor: V
|
||||
visitor: V,
|
||||
) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
@@ -1216,9 +1226,10 @@ mod content {
|
||||
{
|
||||
match self.value {
|
||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)),
|
||||
None => {
|
||||
Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"newtype variant"),)
|
||||
}
|
||||
None => Err(de::Error::invalid_type(
|
||||
de::Unexpected::UnitVariant,
|
||||
&"newtype variant",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1230,8 +1241,14 @@ mod content {
|
||||
Some(Content::Seq(v)) => {
|
||||
de::Deserializer::deserialize_any(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"),),
|
||||
Some(other) => Err(de::Error::invalid_type(
|
||||
other.unexpected(),
|
||||
&"tuple variant",
|
||||
)),
|
||||
None => Err(de::Error::invalid_type(
|
||||
de::Unexpected::UnitVariant,
|
||||
&"tuple variant",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1250,8 +1267,14 @@ mod content {
|
||||
Some(Content::Seq(v)) => {
|
||||
de::Deserializer::deserialize_any(SeqDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"struct variant"),),
|
||||
_ => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"struct variant"),),
|
||||
Some(other) => Err(de::Error::invalid_type(
|
||||
other.unexpected(),
|
||||
&"struct variant",
|
||||
)),
|
||||
_ => Err(de::Error::invalid_type(
|
||||
de::Unexpected::UnitVariant,
|
||||
&"struct variant",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1319,10 +1342,7 @@ mod content {
|
||||
T: de::DeserializeSeed<'de>,
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(value) => {
|
||||
seed.deserialize(ContentDeserializer::new(value))
|
||||
.map(Some)
|
||||
}
|
||||
Some(value) => seed.deserialize(ContentDeserializer::new(value)).map(Some),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
@@ -1458,12 +1478,12 @@ mod content {
|
||||
Ok(value)
|
||||
}
|
||||
Content::Map(ref v) => {
|
||||
let map = v.into_iter()
|
||||
.map(
|
||||
|&(ref k, ref v)| {
|
||||
(ContentRefDeserializer::new(k), ContentRefDeserializer::new(v))
|
||||
},
|
||||
);
|
||||
let map = v.into_iter().map(|&(ref k, ref 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());
|
||||
@@ -1506,38 +1526,35 @@ mod content {
|
||||
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))
|
||||
}
|
||||
ref s @ Content::String(_) | ref s @ Content::Str(_) => (s, None),
|
||||
ref other => {
|
||||
return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),);
|
||||
return Err(de::Error::invalid_type(
|
||||
other.unexpected(),
|
||||
&"string or map",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
visitor.visit_enum(
|
||||
EnumRefDeserializer {
|
||||
variant: variant,
|
||||
value: value,
|
||||
err: PhantomData,
|
||||
},
|
||||
)
|
||||
visitor.visit_enum(EnumRefDeserializer {
|
||||
variant: variant,
|
||||
value: value,
|
||||
err: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
forward_to_deserialize_any! {
|
||||
@@ -1613,9 +1630,10 @@ mod content {
|
||||
{
|
||||
match self.value {
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)),
|
||||
None => {
|
||||
Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"newtype variant"),)
|
||||
}
|
||||
None => Err(de::Error::invalid_type(
|
||||
de::Unexpected::UnitVariant,
|
||||
&"newtype variant",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1627,8 +1645,14 @@ mod content {
|
||||
Some(&Content::Seq(ref v)) => {
|
||||
de::Deserializer::deserialize_any(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"),),
|
||||
Some(other) => Err(de::Error::invalid_type(
|
||||
other.unexpected(),
|
||||
&"tuple variant",
|
||||
)),
|
||||
None => Err(de::Error::invalid_type(
|
||||
de::Unexpected::UnitVariant,
|
||||
&"tuple variant",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1647,8 +1671,14 @@ mod content {
|
||||
Some(&Content::Seq(ref v)) => {
|
||||
de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(other) => Err(de::Error::invalid_type(other.unexpected(), &"struct variant"),),
|
||||
_ => Err(de::Error::invalid_type(de::Unexpected::UnitVariant, &"struct variant"),),
|
||||
Some(other) => Err(de::Error::invalid_type(
|
||||
other.unexpected(),
|
||||
&"struct variant",
|
||||
)),
|
||||
_ => Err(de::Error::invalid_type(
|
||||
de::Unexpected::UnitVariant,
|
||||
&"struct variant",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1716,10 +1746,8 @@ mod content {
|
||||
T: de::DeserializeSeed<'de>,
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(value) => {
|
||||
seed.deserialize(ContentRefDeserializer::new(value))
|
||||
.map(Some)
|
||||
}
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value))
|
||||
.map(Some),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
@@ -1764,8 +1792,7 @@ mod content {
|
||||
match self.iter.next() {
|
||||
Some(&(ref key, ref value)) => {
|
||||
self.value = Some(value);
|
||||
seed.deserialize(ContentRefDeserializer::new(key))
|
||||
.map(Some)
|
||||
seed.deserialize(ContentRefDeserializer::new(key)).map(Some)
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
@@ -1851,7 +1878,11 @@ mod content {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "unit variant {}::{}", self.type_name, self.variant_name)
|
||||
write!(
|
||||
formatter,
|
||||
"unit variant {}::{}",
|
||||
self.type_name, self.variant_name
|
||||
)
|
||||
}
|
||||
|
||||
fn visit_seq<S>(self, _: S) -> Result<(), S::Error>
|
||||
@@ -1891,7 +1922,11 @@ mod content {
|
||||
type Value = ();
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "unit variant {}::{}", self.type_name, self.variant_name)
|
||||
write!(
|
||||
formatter,
|
||||
"unit variant {}::{}",
|
||||
self.type_name, self.variant_name
|
||||
)
|
||||
}
|
||||
|
||||
fn visit_unit<E>(self) -> Result<(), E>
|
||||
@@ -2016,7 +2051,8 @@ where
|
||||
pub struct InPlaceSeed<'a, T: 'a>(pub &'a mut T);
|
||||
|
||||
impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>
|
||||
where T: Deserialize<'de>,
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
type Value = ();
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
|
||||
+96
-86
@@ -8,10 +8,10 @@
|
||||
|
||||
use lib::*;
|
||||
|
||||
use ser::{self, Serialize, Serializer, SerializeMap, SerializeStruct, Impossible};
|
||||
use ser::{self, Impossible, Serialize, SerializeMap, SerializeStruct, Serializer};
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
use self::content::{SerializeTupleVariantAsMapValue, SerializeStructVariantAsMapValue};
|
||||
use self::content::{SerializeStructVariantAsMapValue, SerializeTupleVariantAsMapValue};
|
||||
|
||||
/// Used to check that serde(getter) attributes return the expected type.
|
||||
/// Not public API.
|
||||
@@ -32,15 +32,13 @@ where
|
||||
S: Serializer,
|
||||
T: Serialize,
|
||||
{
|
||||
value.serialize(
|
||||
TaggedSerializer {
|
||||
type_ident: type_ident,
|
||||
variant_ident: variant_ident,
|
||||
tag: tag,
|
||||
variant_name: variant_name,
|
||||
delegate: serializer,
|
||||
},
|
||||
)
|
||||
value.serialize(TaggedSerializer {
|
||||
type_ident: type_ident,
|
||||
variant_ident: variant_ident,
|
||||
tag: tag,
|
||||
variant_name: variant_name,
|
||||
delegate: serializer,
|
||||
})
|
||||
}
|
||||
|
||||
struct TaggedSerializer<S> {
|
||||
@@ -63,8 +61,7 @@ enum Unsupported {
|
||||
Sequence,
|
||||
Tuple,
|
||||
TupleStruct,
|
||||
#[cfg(not(any(feature = "std", feature = "alloc")))]
|
||||
Enum,
|
||||
#[cfg(not(any(feature = "std", feature = "alloc")))] Enum,
|
||||
}
|
||||
|
||||
impl Display for Unsupported {
|
||||
@@ -92,13 +89,10 @@ where
|
||||
S: Serializer,
|
||||
{
|
||||
fn bad_type(self, what: Unsupported) -> S::Error {
|
||||
ser::Error::custom(
|
||||
format_args!(
|
||||
ser::Error::custom(format_args!(
|
||||
"cannot serialize tagged newtype variant {}::{} containing {}",
|
||||
self.type_ident,
|
||||
self.variant_ident,
|
||||
what),
|
||||
)
|
||||
self.type_ident, self.variant_ident, what
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +275,11 @@ where
|
||||
let mut map = try!(self.delegate.serialize_map(Some(2)));
|
||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
||||
try!(map.serialize_key(inner_variant));
|
||||
Ok(SerializeTupleVariantAsMapValue::new(map, inner_variant, len),)
|
||||
Ok(SerializeTupleVariantAsMapValue::new(
|
||||
map,
|
||||
inner_variant,
|
||||
len,
|
||||
))
|
||||
}
|
||||
|
||||
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
||||
@@ -324,7 +322,11 @@ where
|
||||
let mut map = try!(self.delegate.serialize_map(Some(2)));
|
||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
||||
try!(map.serialize_key(inner_variant));
|
||||
Ok(SerializeStructVariantAsMapValue::new(map, inner_variant, len),)
|
||||
Ok(SerializeStructVariantAsMapValue::new(
|
||||
map,
|
||||
inner_variant,
|
||||
len,
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "std", feature = "alloc")))]
|
||||
@@ -402,7 +404,10 @@ mod content {
|
||||
}
|
||||
|
||||
fn end(mut self) -> Result<M::Ok, M::Error> {
|
||||
try!(self.map.serialize_value(&Content::TupleStruct(self.name, self.fields)));
|
||||
try!(
|
||||
self.map
|
||||
.serialize_value(&Content::TupleStruct(self.name, self.fields))
|
||||
);
|
||||
self.map.end()
|
||||
}
|
||||
}
|
||||
@@ -444,7 +449,10 @@ mod content {
|
||||
}
|
||||
|
||||
fn end(mut self) -> Result<M::Ok, M::Error> {
|
||||
try!(self.map.serialize_value(&Content::Struct(self.name, self.fields)));
|
||||
try!(
|
||||
self.map
|
||||
.serialize_value(&Content::Struct(self.name, self.fields))
|
||||
);
|
||||
self.map.end()
|
||||
}
|
||||
}
|
||||
@@ -485,7 +493,12 @@ mod content {
|
||||
TupleVariant(&'static str, u32, &'static str, Vec<Content>),
|
||||
Map(Vec<(Content, Content)>),
|
||||
Struct(&'static str, Vec<(&'static str, Content)>),
|
||||
StructVariant(&'static str, u32, &'static str, Vec<(&'static str, Content)>),
|
||||
StructVariant(
|
||||
&'static str,
|
||||
u32,
|
||||
&'static str,
|
||||
Vec<(&'static str, Content)>,
|
||||
),
|
||||
}
|
||||
|
||||
impl Serialize for Content {
|
||||
@@ -687,7 +700,10 @@ mod content {
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
Ok(Content::NewtypeStruct(name, Box::new(try!(value.serialize(self)))),)
|
||||
Ok(Content::NewtypeStruct(
|
||||
name,
|
||||
Box::new(try!(value.serialize(self))),
|
||||
))
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T: ?Sized>(
|
||||
@@ -700,32 +716,26 @@ mod content {
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
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> {
|
||||
Ok(
|
||||
SerializeSeq {
|
||||
elements: Vec::with_capacity(len.unwrap_or(0)),
|
||||
error: PhantomData,
|
||||
},
|
||||
)
|
||||
Ok(SerializeSeq {
|
||||
elements: Vec::with_capacity(len.unwrap_or(0)),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, E> {
|
||||
Ok(
|
||||
SerializeTuple {
|
||||
elements: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
},
|
||||
)
|
||||
Ok(SerializeTuple {
|
||||
elements: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct(
|
||||
@@ -733,13 +743,11 @@ mod content {
|
||||
name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleStruct, E> {
|
||||
Ok(
|
||||
SerializeTupleStruct {
|
||||
name: name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
},
|
||||
)
|
||||
Ok(SerializeTupleStruct {
|
||||
name: name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant(
|
||||
@@ -749,25 +757,21 @@ mod content {
|
||||
variant: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleVariant, E> {
|
||||
Ok(
|
||||
SerializeTupleVariant {
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
},
|
||||
)
|
||||
Ok(SerializeTupleVariant {
|
||||
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> {
|
||||
Ok(
|
||||
SerializeMap {
|
||||
entries: Vec::with_capacity(len.unwrap_or(0)),
|
||||
key: None,
|
||||
error: PhantomData,
|
||||
},
|
||||
)
|
||||
Ok(SerializeMap {
|
||||
entries: Vec::with_capacity(len.unwrap_or(0)),
|
||||
key: None,
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_struct(
|
||||
@@ -775,13 +779,11 @@ mod content {
|
||||
name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeStruct, E> {
|
||||
Ok(
|
||||
SerializeStruct {
|
||||
name: name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
},
|
||||
)
|
||||
Ok(SerializeStruct {
|
||||
name: name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize_struct_variant(
|
||||
@@ -791,15 +793,13 @@ mod content {
|
||||
variant: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeStructVariant, E> {
|
||||
Ok(
|
||||
SerializeStructVariant {
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
},
|
||||
)
|
||||
Ok(SerializeStructVariant {
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -907,7 +907,12 @@ mod content {
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Content, E> {
|
||||
Ok(Content::TupleVariant(self.name, self.variant_index, self.variant, self.fields),)
|
||||
Ok(Content::TupleVariant(
|
||||
self.name,
|
||||
self.variant_index,
|
||||
self.variant,
|
||||
self.fields,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1013,7 +1018,12 @@ mod content {
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Content, E> {
|
||||
Ok(Content::StructVariant(self.name, self.variant_index, self.variant, self.fields),)
|
||||
Ok(Content::StructVariant(
|
||||
self.name,
|
||||
self.variant_index,
|
||||
self.variant,
|
||||
self.fields,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-10
@@ -464,7 +464,8 @@ impl Serialize for SystemTime {
|
||||
S: Serializer,
|
||||
{
|
||||
use super::SerializeStruct;
|
||||
let duration_since_epoch = self.duration_since(UNIX_EPOCH).expect("SystemTime must be later than UNIX_EPOCH");
|
||||
let duration_since_epoch = self.duration_since(UNIX_EPOCH)
|
||||
.expect("SystemTime must be later than UNIX_EPOCH");
|
||||
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
|
||||
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
|
||||
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
|
||||
@@ -513,10 +514,12 @@ impl Serialize for net::IpAddr {
|
||||
}
|
||||
} else {
|
||||
match *self {
|
||||
net::IpAddr::V4(ref a) =>
|
||||
serializer.serialize_newtype_variant("IpAddr", 0, "V4", a),
|
||||
net::IpAddr::V6(ref a) =>
|
||||
serializer.serialize_newtype_variant("IpAddr", 1, "V6", a),
|
||||
net::IpAddr::V4(ref a) => {
|
||||
serializer.serialize_newtype_variant("IpAddr", 0, "V4", a)
|
||||
}
|
||||
net::IpAddr::V6(ref a) => {
|
||||
serializer.serialize_newtype_variant("IpAddr", 1, "V6", a)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -567,10 +570,12 @@ impl Serialize for net::SocketAddr {
|
||||
}
|
||||
} else {
|
||||
match *self {
|
||||
net::SocketAddr::V4(ref addr) =>
|
||||
serializer.serialize_newtype_variant("SocketAddr", 0, "V4", addr),
|
||||
net::SocketAddr::V6(ref addr) =>
|
||||
serializer.serialize_newtype_variant("SocketAddr", 1, "V6", addr),
|
||||
net::SocketAddr::V4(ref addr) => {
|
||||
serializer.serialize_newtype_variant("SocketAddr", 0, "V4", addr)
|
||||
}
|
||||
net::SocketAddr::V6(ref addr) => {
|
||||
serializer.serialize_newtype_variant("SocketAddr", 1, "V6", addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -600,7 +605,10 @@ impl Serialize for net::SocketAddrV6 {
|
||||
{
|
||||
if serializer.is_human_readable() {
|
||||
const MAX_LEN: usize = 47;
|
||||
debug_assert_eq!(MAX_LEN, "[1001:1002:1003:1004:1005:1006:1007:1008]:65000".len());
|
||||
debug_assert_eq!(
|
||||
MAX_LEN,
|
||||
"[1001:1002:1003:1004:1005:1006:1007:1008]:65000".len()
|
||||
);
|
||||
serialize_display_bounded_length!(self, MAX_LEN, serializer)
|
||||
} else {
|
||||
(self.ip(), self.port()).serialize(serializer)
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
use lib::*;
|
||||
|
||||
use ser::{self, Serialize, SerializeSeq, SerializeTuple, SerializeTupleStruct,
|
||||
SerializeTupleVariant, SerializeMap, SerializeStruct, SerializeStructVariant};
|
||||
use ser::{self, Serialize, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant,
|
||||
SerializeTuple, SerializeTupleStruct, SerializeTupleVariant};
|
||||
|
||||
/// Helper type for implementing a `Serializer` that does not support
|
||||
/// serializing one of the compound types.
|
||||
|
||||
@@ -1412,7 +1412,9 @@ pub trait Serializer: Sized {
|
||||
/// change, as a value serialized in human-readable mode is not required to
|
||||
/// deserialize from the same data in compact mode.
|
||||
#[inline]
|
||||
fn is_human_readable(&self) -> bool { true }
|
||||
fn is_human_readable(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// Returned from `Serializer::serialize_seq`.
|
||||
|
||||
Reference in New Issue
Block a user