mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-15 01:31:02 +00:00
Merge pull request #860 from serde-rs/identifier
Standardize on u32 for struct field index and enum variant index
This commit is contained in:
@@ -1232,7 +1232,7 @@ impl<'de> Deserialize<'de> for Duration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deserializer.deserialize_struct_field(FieldVisitor)
|
deserializer.deserialize_identifier(FieldVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1358,7 +1358,7 @@ impl<'de, Idx: Deserialize<'de>> Deserialize<'de> for std::ops::Range<Idx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deserializer.deserialize_struct_field(FieldVisitor)
|
deserializer.deserialize_identifier(FieldVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -911,8 +911,8 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
where V: Visitor<'de>;
|
where V: Visitor<'de>;
|
||||||
|
|
||||||
/// Hint that the `Deserialize` type is expecting the name of a struct
|
/// Hint that the `Deserialize` type is expecting the name of a struct
|
||||||
/// field.
|
/// field or the discriminant of an enum variant.
|
||||||
fn deserialize_struct_field<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where V: Visitor<'de>;
|
where V: Visitor<'de>;
|
||||||
|
|
||||||
/// Hint that the `Deserialize` type is expecting an enum value with a
|
/// Hint that the `Deserialize` type is expecting an enum value with a
|
||||||
|
|||||||
+11
-11
@@ -108,7 +108,7 @@ impl<'de, E> de::Deserializer<'de> for UnitDeserializer<E>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
|
||||||
seq_fixed_size bytes map unit_struct newtype_struct tuple_struct struct
|
seq_fixed_size bytes map unit_struct newtype_struct tuple_struct struct
|
||||||
struct_field tuple enum ignored_any byte_buf
|
identifier tuple enum ignored_any byte_buf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
@@ -155,7 +155,7 @@ macro_rules! primitive_deserializer {
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit
|
||||||
option seq seq_fixed_size bytes map unit_struct newtype_struct
|
option seq seq_fixed_size bytes map unit_struct newtype_struct
|
||||||
tuple_struct struct struct_field tuple enum ignored_any byte_buf
|
tuple_struct struct identifier tuple enum ignored_any byte_buf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
@@ -208,7 +208,7 @@ impl<'de, E> de::Deserializer<'de> for U32Deserializer<E>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
||||||
struct struct_field tuple ignored_any byte_buf
|
struct identifier tuple ignored_any byte_buf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
@@ -286,7 +286,7 @@ impl<'de, 'a, E> de::Deserializer<'de> for StrDeserializer<'a, E>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
||||||
struct struct_field tuple ignored_any byte_buf
|
struct identifier tuple ignored_any byte_buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ impl<'de, E> de::Deserializer<'de> for StringDeserializer<E>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
||||||
struct struct_field tuple ignored_any byte_buf
|
struct identifier tuple ignored_any byte_buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,7 +420,7 @@ impl<'de, 'a, E> de::Deserializer<'de> for CowStrDeserializer<'a, E>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
||||||
struct struct_field tuple ignored_any byte_buf
|
struct identifier tuple ignored_any byte_buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,7 +495,7 @@ impl<'de, I, T, E> de::Deserializer<'de> for SeqDeserializer<I, E>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
||||||
struct struct_field tuple enum ignored_any byte_buf
|
struct identifier tuple enum ignored_any byte_buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,7 +603,7 @@ impl<'de, V_> de::Deserializer<'de> for SeqVisitorDeserializer<V_>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
||||||
struct struct_field tuple enum ignored_any byte_buf
|
struct identifier tuple enum ignored_any byte_buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,7 +707,7 @@ impl<'de, I, E> de::Deserializer<'de> for MapDeserializer<'de, I, E>
|
|||||||
|
|
||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
bytes map unit_struct newtype_struct tuple_struct struct struct_field
|
bytes map unit_struct newtype_struct tuple_struct struct identifier
|
||||||
tuple enum ignored_any byte_buf
|
tuple enum ignored_any byte_buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -804,7 +804,7 @@ impl<'de, A, B, E> de::Deserializer<'de> for PairDeserializer<A, B, E>
|
|||||||
|
|
||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
bytes map unit_struct newtype_struct tuple_struct struct struct_field
|
bytes map unit_struct newtype_struct tuple_struct struct identifier
|
||||||
tuple enum ignored_any byte_buf
|
tuple enum ignored_any byte_buf
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -945,7 +945,7 @@ impl<'de, V_> de::Deserializer<'de> for MapVisitorDeserializer<V_>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
||||||
struct struct_field tuple enum ignored_any byte_buf
|
struct identifier tuple enum ignored_any byte_buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -89,8 +89,8 @@ macro_rules! forward_to_deserialize_helper {
|
|||||||
(struct) => {
|
(struct) => {
|
||||||
forward_to_deserialize_method!{deserialize_struct(&'static str, &'static [&'static str])}
|
forward_to_deserialize_method!{deserialize_struct(&'static str, &'static [&'static str])}
|
||||||
};
|
};
|
||||||
(struct_field) => {
|
(identifier) => {
|
||||||
forward_to_deserialize_method!{deserialize_struct_field()}
|
forward_to_deserialize_method!{deserialize_identifier()}
|
||||||
};
|
};
|
||||||
(tuple) => {
|
(tuple) => {
|
||||||
forward_to_deserialize_method!{deserialize_tuple(usize)}
|
forward_to_deserialize_method!{deserialize_tuple(usize)}
|
||||||
@@ -143,7 +143,7 @@ macro_rules! forward_to_deserialize_helper {
|
|||||||
/// # forward_to_deserialize! {
|
/// # forward_to_deserialize! {
|
||||||
/// # u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
/// # u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
/// # seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
/// # seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
||||||
/// # tuple_struct struct struct_field tuple enum ignored_any
|
/// # tuple_struct struct identifier tuple enum ignored_any
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
@@ -176,7 +176,7 @@ macro_rules! forward_to_deserialize_helper {
|
|||||||
/// forward_to_deserialize! {
|
/// forward_to_deserialize! {
|
||||||
/// bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
/// bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
/// seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
/// seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
||||||
/// tuple_struct struct struct_field tuple enum ignored_any
|
/// tuple_struct struct identifier tuple enum ignored_any
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
/// #
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ pub fn missing_field<'de, V, E>(field: &'static str) -> Result<V, E>
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
|
||||||
seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
||||||
tuple_struct struct struct_field tuple enum ignored_any
|
tuple_struct struct identifier tuple enum ignored_any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -855,7 +855,7 @@ mod content {
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
|
||||||
seq_fixed_size bytes byte_buf map unit_struct tuple_struct struct
|
seq_fixed_size bytes byte_buf map unit_struct tuple_struct struct
|
||||||
struct_field tuple ignored_any
|
identifier tuple ignored_any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -996,7 +996,7 @@ mod content {
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
||||||
tuple_struct struct struct_field tuple enum ignored_any
|
tuple_struct struct identifier tuple enum ignored_any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1085,7 +1085,7 @@ mod content {
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
||||||
tuple_struct struct struct_field tuple enum ignored_any
|
tuple_struct struct identifier tuple enum ignored_any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1202,7 +1202,7 @@ mod content {
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit seq
|
||||||
seq_fixed_size bytes byte_buf map unit_struct tuple_struct struct
|
seq_fixed_size bytes byte_buf map unit_struct tuple_struct struct
|
||||||
struct_field tuple ignored_any
|
identifier tuple ignored_any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1341,7 +1341,7 @@ mod content {
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
||||||
tuple_struct struct struct_field tuple enum ignored_any
|
tuple_struct struct identifier tuple enum ignored_any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1430,7 +1430,7 @@ mod content {
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
|
||||||
tuple_struct struct struct_field tuple enum ignored_any
|
tuple_struct struct identifier tuple enum ignored_any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,13 +66,13 @@ macro_rules! __serialize_unimplemented_helper {
|
|||||||
__serialize_unimplemented_method!(serialize_unit_struct(&str) -> Ok);
|
__serialize_unimplemented_method!(serialize_unit_struct(&str) -> Ok);
|
||||||
};
|
};
|
||||||
(unit_variant) => {
|
(unit_variant) => {
|
||||||
__serialize_unimplemented_method!(serialize_unit_variant(&str, usize, &str) -> Ok);
|
__serialize_unimplemented_method!(serialize_unit_variant(&str, u32, &str) -> Ok);
|
||||||
};
|
};
|
||||||
(newtype_struct) => {
|
(newtype_struct) => {
|
||||||
__serialize_unimplemented_method!(serialize_newtype_struct<T>(&str, &T) -> Ok);
|
__serialize_unimplemented_method!(serialize_newtype_struct<T>(&str, &T) -> Ok);
|
||||||
};
|
};
|
||||||
(newtype_variant) => {
|
(newtype_variant) => {
|
||||||
__serialize_unimplemented_method!(serialize_newtype_variant<T>(&str, usize, &str, &T) -> Ok);
|
__serialize_unimplemented_method!(serialize_newtype_variant<T>(&str, u32, &str, &T) -> Ok);
|
||||||
};
|
};
|
||||||
(seq) => {
|
(seq) => {
|
||||||
type SerializeSeq = $crate::ser::Impossible<Self::Ok, Self::Error>;
|
type SerializeSeq = $crate::ser::Impossible<Self::Ok, Self::Error>;
|
||||||
@@ -91,7 +91,7 @@ macro_rules! __serialize_unimplemented_helper {
|
|||||||
};
|
};
|
||||||
(tuple_variant) => {
|
(tuple_variant) => {
|
||||||
type SerializeTupleVariant = $crate::ser::Impossible<Self::Ok, Self::Error>;
|
type SerializeTupleVariant = $crate::ser::Impossible<Self::Ok, Self::Error>;
|
||||||
__serialize_unimplemented_method!(serialize_tuple_variant(&str, usize, &str, usize) -> SerializeTupleVariant);
|
__serialize_unimplemented_method!(serialize_tuple_variant(&str, u32, &str, usize) -> SerializeTupleVariant);
|
||||||
};
|
};
|
||||||
(map) => {
|
(map) => {
|
||||||
type SerializeMap = $crate::ser::Impossible<Self::Ok, Self::Error>;
|
type SerializeMap = $crate::ser::Impossible<Self::Ok, Self::Error>;
|
||||||
@@ -103,7 +103,7 @@ macro_rules! __serialize_unimplemented_helper {
|
|||||||
};
|
};
|
||||||
(struct_variant) => {
|
(struct_variant) => {
|
||||||
type SerializeStructVariant = $crate::ser::Impossible<Self::Ok, Self::Error>;
|
type SerializeStructVariant = $crate::ser::Impossible<Self::Ok, Self::Error>;
|
||||||
__serialize_unimplemented_method!(serialize_struct_variant(&str, usize, &str, usize) -> SerializeStructVariant);
|
__serialize_unimplemented_method!(serialize_struct_variant(&str, u32, &str, usize) -> SerializeStructVariant);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-16
@@ -190,7 +190,7 @@ impl<S> Serializer for TaggedSerializer<S>
|
|||||||
|
|
||||||
fn serialize_unit_variant(self,
|
fn serialize_unit_variant(self,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: usize,
|
_: u32,
|
||||||
inner_variant: &'static str)
|
inner_variant: &'static str)
|
||||||
-> Result<Self::Ok, Self::Error> {
|
-> Result<Self::Ok, Self::Error> {
|
||||||
let mut map = try!(self.delegate.serialize_map(Some(2)));
|
let mut map = try!(self.delegate.serialize_map(Some(2)));
|
||||||
@@ -210,7 +210,7 @@ impl<S> Serializer for TaggedSerializer<S>
|
|||||||
|
|
||||||
fn serialize_newtype_variant<T: ?Sized>(self,
|
fn serialize_newtype_variant<T: ?Sized>(self,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: usize,
|
_: u32,
|
||||||
inner_variant: &'static str,
|
inner_variant: &'static str,
|
||||||
inner_value: &T)
|
inner_value: &T)
|
||||||
-> Result<Self::Ok, Self::Error>
|
-> Result<Self::Ok, Self::Error>
|
||||||
@@ -244,7 +244,7 @@ impl<S> Serializer for TaggedSerializer<S>
|
|||||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
#[cfg(not(any(feature = "std", feature = "collections")))]
|
||||||
fn serialize_tuple_variant(self,
|
fn serialize_tuple_variant(self,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: usize,
|
_: u32,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: usize)
|
_: usize)
|
||||||
-> Result<Self::SerializeTupleVariant, Self::Error> {
|
-> Result<Self::SerializeTupleVariant, Self::Error> {
|
||||||
@@ -256,7 +256,7 @@ impl<S> Serializer for TaggedSerializer<S>
|
|||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
fn serialize_tuple_variant(self,
|
fn serialize_tuple_variant(self,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: usize,
|
_: u32,
|
||||||
inner_variant: &'static str,
|
inner_variant: &'static str,
|
||||||
len: usize)
|
len: usize)
|
||||||
-> Result<Self::SerializeTupleVariant, Self::Error> {
|
-> Result<Self::SerializeTupleVariant, Self::Error> {
|
||||||
@@ -284,7 +284,7 @@ impl<S> Serializer for TaggedSerializer<S>
|
|||||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
#[cfg(not(any(feature = "std", feature = "collections")))]
|
||||||
fn serialize_struct_variant(self,
|
fn serialize_struct_variant(self,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: usize,
|
_: u32,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: usize)
|
_: usize)
|
||||||
-> Result<Self::SerializeStructVariant, Self::Error> {
|
-> Result<Self::SerializeStructVariant, Self::Error> {
|
||||||
@@ -296,7 +296,7 @@ impl<S> Serializer for TaggedSerializer<S>
|
|||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
fn serialize_struct_variant(self,
|
fn serialize_struct_variant(self,
|
||||||
_: &'static str,
|
_: &'static str,
|
||||||
_: usize,
|
_: u32,
|
||||||
inner_variant: &'static str,
|
inner_variant: &'static str,
|
||||||
len: usize)
|
len: usize)
|
||||||
-> Result<Self::SerializeStructVariant, Self::Error> {
|
-> Result<Self::SerializeStructVariant, Self::Error> {
|
||||||
@@ -450,18 +450,18 @@ mod content {
|
|||||||
|
|
||||||
Unit,
|
Unit,
|
||||||
UnitStruct(&'static str),
|
UnitStruct(&'static str),
|
||||||
UnitVariant(&'static str, usize, &'static str),
|
UnitVariant(&'static str, u32, &'static str),
|
||||||
NewtypeStruct(&'static str, Box<Content>),
|
NewtypeStruct(&'static str, Box<Content>),
|
||||||
NewtypeVariant(&'static str, usize, &'static str, Box<Content>),
|
NewtypeVariant(&'static str, u32, &'static str, Box<Content>),
|
||||||
|
|
||||||
Seq(Vec<Content>),
|
Seq(Vec<Content>),
|
||||||
SeqFixedSize(Vec<Content>),
|
SeqFixedSize(Vec<Content>),
|
||||||
Tuple(Vec<Content>),
|
Tuple(Vec<Content>),
|
||||||
TupleStruct(&'static str, Vec<Content>),
|
TupleStruct(&'static str, Vec<Content>),
|
||||||
TupleVariant(&'static str, usize, &'static str, Vec<Content>),
|
TupleVariant(&'static str, u32, &'static str, Vec<Content>),
|
||||||
Map(Vec<(Content, Content)>),
|
Map(Vec<(Content, Content)>),
|
||||||
Struct(&'static str, Vec<(&'static str, Content)>),
|
Struct(&'static str, Vec<(&'static str, Content)>),
|
||||||
StructVariant(&'static str, usize, &'static str, Vec<(&'static str, Content)>),
|
StructVariant(&'static str, u32, &'static str, Vec<(&'static str, Content)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for Content {
|
impl Serialize for Content {
|
||||||
@@ -651,7 +651,7 @@ mod content {
|
|||||||
|
|
||||||
fn serialize_unit_variant(self,
|
fn serialize_unit_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str)
|
variant: &'static str)
|
||||||
-> Result<Content, E> {
|
-> Result<Content, E> {
|
||||||
Ok(Content::UnitVariant(name, variant_index, variant))
|
Ok(Content::UnitVariant(name, variant_index, variant))
|
||||||
@@ -666,7 +666,7 @@ mod content {
|
|||||||
|
|
||||||
fn serialize_newtype_variant<T: ?Sized + Serialize>(self,
|
fn serialize_newtype_variant<T: ?Sized + Serialize>(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
value: &T)
|
value: &T)
|
||||||
-> Result<Content, E> {
|
-> Result<Content, E> {
|
||||||
@@ -712,7 +712,7 @@ mod content {
|
|||||||
|
|
||||||
fn serialize_tuple_variant(self,
|
fn serialize_tuple_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
len: usize)
|
len: usize)
|
||||||
-> Result<Self::SerializeTupleVariant, E> {
|
-> Result<Self::SerializeTupleVariant, E> {
|
||||||
@@ -743,7 +743,7 @@ mod content {
|
|||||||
|
|
||||||
fn serialize_struct_variant(self,
|
fn serialize_struct_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
len: usize)
|
len: usize)
|
||||||
-> Result<Self::SerializeStructVariant, E> {
|
-> Result<Self::SerializeStructVariant, E> {
|
||||||
@@ -831,7 +831,7 @@ mod content {
|
|||||||
|
|
||||||
struct SerializeTupleVariant<E> {
|
struct SerializeTupleVariant<E> {
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
fields: Vec<Content>,
|
fields: Vec<Content>,
|
||||||
error: PhantomData<E>,
|
error: PhantomData<E>,
|
||||||
@@ -922,7 +922,7 @@ mod content {
|
|||||||
|
|
||||||
struct SerializeStructVariant<E> {
|
struct SerializeStructVariant<E> {
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
fields: Vec<(&'static str, Content)>,
|
fields: Vec<(&'static str, Content)>,
|
||||||
error: PhantomData<E>,
|
error: PhantomData<E>,
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ pub trait Serializer: Sized {
|
|||||||
/// ```
|
/// ```
|
||||||
fn serialize_unit_variant(self,
|
fn serialize_unit_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str)
|
variant: &'static str)
|
||||||
-> Result<Self::Ok, Self::Error>;
|
-> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -504,7 +504,7 @@ pub trait Serializer: Sized {
|
|||||||
/// ```
|
/// ```
|
||||||
fn serialize_newtype_variant<T: ?Sized + Serialize>(self,
|
fn serialize_newtype_variant<T: ?Sized + Serialize>(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
value: &T)
|
value: &T)
|
||||||
-> Result<Self::Ok, Self::Error>;
|
-> Result<Self::Ok, Self::Error>;
|
||||||
@@ -686,7 +686,7 @@ pub trait Serializer: Sized {
|
|||||||
/// ```
|
/// ```
|
||||||
fn serialize_tuple_variant(self,
|
fn serialize_tuple_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
len: usize)
|
len: usize)
|
||||||
-> Result<Self::SerializeTupleVariant, Self::Error>;
|
-> Result<Self::SerializeTupleVariant, Self::Error>;
|
||||||
@@ -806,7 +806,7 @@ pub trait Serializer: Sized {
|
|||||||
/// ```
|
/// ```
|
||||||
fn serialize_struct_variant(self,
|
fn serialize_struct_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
len: usize)
|
len: usize)
|
||||||
-> Result<Self::SerializeStructVariant, Self::Error>;
|
-> Result<Self::SerializeStructVariant, Self::Error>;
|
||||||
|
|||||||
@@ -1274,7 +1274,7 @@ fn deserialize_field_visitor(fields: Vec<(String, Ident)>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_serde::Deserializer::deserialize_struct_field(__deserializer, __FieldVisitor)
|
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -6,6 +6,8 @@ use fragment::{Fragment, Stmts, Match};
|
|||||||
use internals::ast::{Body, Field, Item, Style, Variant};
|
use internals::ast::{Body, Field, Item, Style, Variant};
|
||||||
use internals::{self, attr};
|
use internals::{self, attr};
|
||||||
|
|
||||||
|
use std::u32;
|
||||||
|
|
||||||
pub fn expand_derive_serialize(item: &syn::DeriveInput) -> Result<Tokens, String> {
|
pub fn expand_derive_serialize(item: &syn::DeriveInput) -> Result<Tokens, String> {
|
||||||
let ctxt = internals::Ctxt::new();
|
let ctxt = internals::Ctxt::new();
|
||||||
let item = Item::from_ast(&ctxt, item);
|
let item = Item::from_ast(&ctxt, item);
|
||||||
@@ -210,6 +212,8 @@ fn serialize_struct(params: &Parameters,
|
|||||||
fields: &[Field],
|
fields: &[Field],
|
||||||
item_attrs: &attr::Item)
|
item_attrs: &attr::Item)
|
||||||
-> Fragment {
|
-> Fragment {
|
||||||
|
assert!(fields.len() as u64 <= u32::MAX as u64);
|
||||||
|
|
||||||
let serialize_fields =
|
let serialize_fields =
|
||||||
serialize_struct_visitor(fields,
|
serialize_struct_visitor(fields,
|
||||||
params,
|
params,
|
||||||
@@ -247,6 +251,8 @@ fn serialize_item_enum(params: &Parameters,
|
|||||||
variants: &[Variant],
|
variants: &[Variant],
|
||||||
item_attrs: &attr::Item)
|
item_attrs: &attr::Item)
|
||||||
-> Fragment {
|
-> Fragment {
|
||||||
|
assert!(variants.len() as u64 <= u32::MAX as u64);
|
||||||
|
|
||||||
let self_var = ¶ms.self_var;
|
let self_var = ¶ms.self_var;
|
||||||
|
|
||||||
let arms: Vec<_> = variants.iter()
|
let arms: Vec<_> = variants.iter()
|
||||||
@@ -254,7 +260,7 @@ fn serialize_item_enum(params: &Parameters,
|
|||||||
.map(|(variant_index, variant)| {
|
.map(|(variant_index, variant)| {
|
||||||
serialize_variant(params,
|
serialize_variant(params,
|
||||||
variant,
|
variant,
|
||||||
variant_index,
|
variant_index as u32,
|
||||||
item_attrs)
|
item_attrs)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@@ -268,7 +274,7 @@ fn serialize_item_enum(params: &Parameters,
|
|||||||
|
|
||||||
fn serialize_variant(params: &Parameters,
|
fn serialize_variant(params: &Parameters,
|
||||||
variant: &Variant,
|
variant: &Variant,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
item_attrs: &attr::Item)
|
item_attrs: &attr::Item)
|
||||||
-> Tokens {
|
-> Tokens {
|
||||||
let this = ¶ms.this;
|
let this = ¶ms.this;
|
||||||
@@ -349,7 +355,7 @@ fn serialize_variant(params: &Parameters,
|
|||||||
|
|
||||||
fn serialize_externally_tagged_variant(params: &Parameters,
|
fn serialize_externally_tagged_variant(params: &Parameters,
|
||||||
variant: &Variant,
|
variant: &Variant,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
item_attrs: &attr::Item)
|
item_attrs: &attr::Item)
|
||||||
-> Fragment {
|
-> Fragment {
|
||||||
let type_name = item_attrs.name().serialize_name();
|
let type_name = item_attrs.name().serialize_name();
|
||||||
@@ -587,7 +593,7 @@ fn serialize_untagged_variant(params: &Parameters,
|
|||||||
enum TupleVariant {
|
enum TupleVariant {
|
||||||
ExternallyTagged {
|
ExternallyTagged {
|
||||||
type_name: String,
|
type_name: String,
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant_name: String,
|
variant_name: String,
|
||||||
},
|
},
|
||||||
Untagged,
|
Untagged,
|
||||||
@@ -637,7 +643,7 @@ fn serialize_tuple_variant(context: TupleVariant,
|
|||||||
|
|
||||||
enum StructVariant<'a> {
|
enum StructVariant<'a> {
|
||||||
ExternallyTagged {
|
ExternallyTagged {
|
||||||
variant_index: usize,
|
variant_index: u32,
|
||||||
variant_name: String,
|
variant_name: String,
|
||||||
},
|
},
|
||||||
InternallyTagged { tag: &'a str, variant_name: String },
|
InternallyTagged { tag: &'a str, variant_name: String },
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
|||||||
|
|
||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit
|
||||||
seq bytes byte_buf map struct_field ignored_any
|
seq bytes byte_buf map identifier ignored_any
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error>
|
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Error>
|
||||||
@@ -645,6 +645,6 @@ impl<'de> de::Deserializer<'de> for BytesDeserializer {
|
|||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
|
||||||
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
seq seq_fixed_size bytes map unit_struct newtype_struct tuple_struct
|
||||||
struct struct_field tuple enum ignored_any byte_buf
|
struct identifier tuple enum ignored_any byte_buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ impl<'s, 'a> ser::Serializer for &'s mut Serializer<'a> {
|
|||||||
|
|
||||||
fn serialize_unit_variant(self,
|
fn serialize_unit_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
_variant_index: usize,
|
_variant_index: u32,
|
||||||
variant: &'static str)
|
variant: &'static str)
|
||||||
-> Result<(), Error> {
|
-> Result<(), Error> {
|
||||||
if self.tokens.first() == Some(&Token::Enum(name)) {
|
if self.tokens.first() == Some(&Token::Enum(name)) {
|
||||||
@@ -168,7 +168,7 @@ impl<'s, 'a> ser::Serializer for &'s mut Serializer<'a> {
|
|||||||
|
|
||||||
fn serialize_newtype_variant<T: ?Sized>(self,
|
fn serialize_newtype_variant<T: ?Sized>(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
_variant_index: usize,
|
_variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
value: &T)
|
value: &T)
|
||||||
-> Result<(), Error>
|
-> Result<(), Error>
|
||||||
@@ -217,7 +217,7 @@ impl<'s, 'a> ser::Serializer for &'s mut Serializer<'a> {
|
|||||||
|
|
||||||
fn serialize_tuple_variant(self,
|
fn serialize_tuple_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
_variant_index: usize,
|
_variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
len: usize)
|
len: usize)
|
||||||
-> Result<Self, Error> {
|
-> Result<Self, Error> {
|
||||||
@@ -237,7 +237,7 @@ impl<'s, 'a> ser::Serializer for &'s mut Serializer<'a> {
|
|||||||
|
|
||||||
fn serialize_struct_variant(self,
|
fn serialize_struct_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
_variant_index: usize,
|
_variant_index: u32,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
len: usize)
|
len: usize)
|
||||||
-> Result<Self, Error> {
|
-> Result<Self, Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user