mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 03:27:56 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 964a2dd4d1 | |||
| 8a21bbc720 | |||
| 4dba260ad7 | |||
| 1d3044fa28 | |||
| d1f0112bfb | |||
| 3f25cd9a7e | |||
| 45a36f1219 | |||
| 529a1cfedb | |||
| 219abd2e00 | |||
| 4bd10528a0 | |||
| b82bba2d0a | |||
| 17c175a1a6 | |||
| 763ab9c2a1 | |||
| 30b8036efa | |||
| 89bb16da6b | |||
| d00a895902 | |||
| 393b19ee8a | |||
| e68888d475 | |||
| 6277079152 |
+8
-2
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "0.9.6"
|
version = "0.9.7"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
@@ -8,7 +8,7 @@ homepage = "https://serde.rs"
|
|||||||
repository = "https://github.com/serde-rs/serde"
|
repository = "https://github.com/serde-rs/serde"
|
||||||
documentation = "https://docs.serde.rs/serde/"
|
documentation = "https://docs.serde.rs/serde/"
|
||||||
readme = "../README.md"
|
readme = "../README.md"
|
||||||
keywords = ["serde", "serialization"]
|
keywords = ["serde", "serialization", "no_std"]
|
||||||
categories = ["encoding"]
|
categories = ["encoding"]
|
||||||
include = ["Cargo.toml", "src/**/*.rs"]
|
include = ["Cargo.toml", "src/**/*.rs"]
|
||||||
|
|
||||||
@@ -24,5 +24,11 @@ alloc = ["unstable"]
|
|||||||
collections = ["alloc"]
|
collections = ["alloc"]
|
||||||
unstable-testing = ["unstable", "std"]
|
unstable-testing = ["unstable", "std"]
|
||||||
|
|
||||||
|
# to get serde_derive picked up by play.integer32.com
|
||||||
|
playground = ["serde_derive"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde_derive = { version = "0.9", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = "0.9"
|
serde_derive = "0.9"
|
||||||
|
|||||||
+109
-91
@@ -35,9 +35,9 @@ use de::{
|
|||||||
///
|
///
|
||||||
/// Not public API. Use serde-value instead.
|
/// Not public API. Use serde-value instead.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Content<E> {
|
pub enum Content {
|
||||||
// Don't mind the PhantomData, just need to use E somewhere.
|
// Don't mind the PhantomData, just need to use E somewhere.
|
||||||
Bool(bool, PhantomData<E>),
|
Bool(bool),
|
||||||
|
|
||||||
U8(u8),
|
U8(u8),
|
||||||
U16(u16),
|
U16(u16),
|
||||||
@@ -57,36 +57,26 @@ pub enum Content<E> {
|
|||||||
Bytes(Vec<u8>),
|
Bytes(Vec<u8>),
|
||||||
|
|
||||||
None,
|
None,
|
||||||
Some(Box<Content<E>>),
|
Some(Box<Content>),
|
||||||
|
|
||||||
Unit,
|
Unit,
|
||||||
Newtype(Box<Content<E>>),
|
Newtype(Box<Content>),
|
||||||
Seq(Vec<Content<E>>),
|
Seq(Vec<Content>),
|
||||||
Map(Vec<(Content<E>, Content<E>)>),
|
Map(Vec<(Content, Content)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Deserialize for Content<E> {
|
impl Deserialize for Content {
|
||||||
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
|
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
// Untagged and internally tagged enums are only supported in
|
// Untagged and internally tagged enums are only supported in
|
||||||
// self-describing formats.
|
// self-describing formats.
|
||||||
deserializer.deserialize(ContentVisitor::new())
|
deserializer.deserialize(ContentVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContentVisitor<E> {
|
struct ContentVisitor;
|
||||||
err: PhantomData<E>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> ContentVisitor<E> {
|
impl Visitor for ContentVisitor {
|
||||||
fn new() -> Self {
|
type Value = Content;
|
||||||
ContentVisitor {
|
|
||||||
err: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> Visitor for ContentVisitor<E> {
|
|
||||||
type Value = Content<E>;
|
|
||||||
|
|
||||||
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt.write_str("any value")
|
fmt.write_str("any value")
|
||||||
@@ -95,7 +85,7 @@ impl<E> Visitor for ContentVisitor<E> {
|
|||||||
fn visit_bool<F>(self, value: bool) -> Result<Self::Value, F>
|
fn visit_bool<F>(self, value: bool) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
Ok(Content::Bool(value, PhantomData))
|
Ok(Content::Bool(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i8<F>(self, value: i8) -> Result<Self::Value, F>
|
fn visit_i8<F>(self, value: i8) -> Result<Self::Value, F>
|
||||||
@@ -242,27 +232,25 @@ impl<E> Visitor for ContentVisitor<E> {
|
|||||||
/// This is the type of the map keys in an internally tagged enum.
|
/// This is the type of the map keys in an internally tagged enum.
|
||||||
///
|
///
|
||||||
/// Not public API.
|
/// Not public API.
|
||||||
pub enum TagOrContent<E> {
|
pub enum TagOrContent {
|
||||||
Tag,
|
Tag,
|
||||||
Content(Content<E>),
|
Content(Content),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TagOrContentVisitor<E> {
|
struct TagOrContentVisitor {
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
err: PhantomData<E>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> TagOrContentVisitor<E> {
|
impl TagOrContentVisitor {
|
||||||
fn new(name: &'static str) -> Self {
|
fn new(name: &'static str) -> Self {
|
||||||
TagOrContentVisitor {
|
TagOrContentVisitor {
|
||||||
name: name,
|
name: name,
|
||||||
err: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> DeserializeSeed for TagOrContentVisitor<E> {
|
impl DeserializeSeed for TagOrContentVisitor {
|
||||||
type Value = TagOrContent<E>;
|
type Value = TagOrContent;
|
||||||
|
|
||||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||||
where D: Deserializer
|
where D: Deserializer
|
||||||
@@ -273,8 +261,8 @@ impl<E> DeserializeSeed for TagOrContentVisitor<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Visitor for TagOrContentVisitor<E> {
|
impl Visitor for TagOrContentVisitor {
|
||||||
type Value = TagOrContent<E>;
|
type Value = TagOrContent;
|
||||||
|
|
||||||
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "a type tag `{}` or any other value", self.name)
|
write!(fmt, "a type tag `{}` or any other value", self.name)
|
||||||
@@ -283,73 +271,73 @@ impl<E> Visitor for TagOrContentVisitor<E> {
|
|||||||
fn visit_bool<F>(self, value: bool) -> Result<Self::Value, F>
|
fn visit_bool<F>(self, value: bool) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_bool(value).map(TagOrContent::Content)
|
ContentVisitor.visit_bool(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i8<F>(self, value: i8) -> Result<Self::Value, F>
|
fn visit_i8<F>(self, value: i8) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_i8(value).map(TagOrContent::Content)
|
ContentVisitor.visit_i8(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i16<F>(self, value: i16) -> Result<Self::Value, F>
|
fn visit_i16<F>(self, value: i16) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_i16(value).map(TagOrContent::Content)
|
ContentVisitor.visit_i16(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i32<F>(self, value: i32) -> Result<Self::Value, F>
|
fn visit_i32<F>(self, value: i32) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_i32(value).map(TagOrContent::Content)
|
ContentVisitor.visit_i32(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_i64<F>(self, value: i64) -> Result<Self::Value, F>
|
fn visit_i64<F>(self, value: i64) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_i64(value).map(TagOrContent::Content)
|
ContentVisitor.visit_i64(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u8<F>(self, value: u8) -> Result<Self::Value, F>
|
fn visit_u8<F>(self, value: u8) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_u8(value).map(TagOrContent::Content)
|
ContentVisitor.visit_u8(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u16<F>(self, value: u16) -> Result<Self::Value, F>
|
fn visit_u16<F>(self, value: u16) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_u16(value).map(TagOrContent::Content)
|
ContentVisitor.visit_u16(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u32<F>(self, value: u32) -> Result<Self::Value, F>
|
fn visit_u32<F>(self, value: u32) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_u32(value).map(TagOrContent::Content)
|
ContentVisitor.visit_u32(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u64<F>(self, value: u64) -> Result<Self::Value, F>
|
fn visit_u64<F>(self, value: u64) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_u64(value).map(TagOrContent::Content)
|
ContentVisitor.visit_u64(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_f32<F>(self, value: f32) -> Result<Self::Value, F>
|
fn visit_f32<F>(self, value: f32) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_f32(value).map(TagOrContent::Content)
|
ContentVisitor.visit_f32(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_f64<F>(self, value: f64) -> Result<Self::Value, F>
|
fn visit_f64<F>(self, value: f64) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_f64(value).map(TagOrContent::Content)
|
ContentVisitor.visit_f64(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_char<F>(self, value: char) -> Result<Self::Value, F>
|
fn visit_char<F>(self, value: char) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_char(value).map(TagOrContent::Content)
|
ContentVisitor.visit_char(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_str<F>(self, value: &str) -> Result<Self::Value, F>
|
fn visit_str<F>(self, value: &str) -> Result<Self::Value, F>
|
||||||
@@ -358,7 +346,7 @@ impl<E> Visitor for TagOrContentVisitor<E> {
|
|||||||
if value == self.name {
|
if value == self.name {
|
||||||
Ok(TagOrContent::Tag)
|
Ok(TagOrContent::Tag)
|
||||||
} else {
|
} else {
|
||||||
ContentVisitor::new().visit_str(value).map(TagOrContent::Content)
|
ContentVisitor.visit_str(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +356,7 @@ impl<E> Visitor for TagOrContentVisitor<E> {
|
|||||||
if value == self.name {
|
if value == self.name {
|
||||||
Ok(TagOrContent::Tag)
|
Ok(TagOrContent::Tag)
|
||||||
} else {
|
} else {
|
||||||
ContentVisitor::new().visit_string(value).map(TagOrContent::Content)
|
ContentVisitor.visit_string(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,7 +366,7 @@ impl<E> Visitor for TagOrContentVisitor<E> {
|
|||||||
if value == self.name.as_bytes() {
|
if value == self.name.as_bytes() {
|
||||||
Ok(TagOrContent::Tag)
|
Ok(TagOrContent::Tag)
|
||||||
} else {
|
} else {
|
||||||
ContentVisitor::new().visit_bytes(value).map(TagOrContent::Content)
|
ContentVisitor.visit_bytes(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,84 +376,82 @@ impl<E> Visitor for TagOrContentVisitor<E> {
|
|||||||
if value == self.name.as_bytes() {
|
if value == self.name.as_bytes() {
|
||||||
Ok(TagOrContent::Tag)
|
Ok(TagOrContent::Tag)
|
||||||
} else {
|
} else {
|
||||||
ContentVisitor::new().visit_byte_buf(value).map(TagOrContent::Content)
|
ContentVisitor.visit_byte_buf(value).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_unit<F>(self) -> Result<Self::Value, F>
|
fn visit_unit<F>(self) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_unit().map(TagOrContent::Content)
|
ContentVisitor.visit_unit().map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_none<F>(self) -> Result<Self::Value, F>
|
fn visit_none<F>(self) -> Result<Self::Value, F>
|
||||||
where F: de::Error
|
where F: de::Error
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_none().map(TagOrContent::Content)
|
ContentVisitor.visit_none().map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||||
where D: Deserializer
|
where D: Deserializer
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_some(deserializer).map(TagOrContent::Content)
|
ContentVisitor.visit_some(deserializer).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||||
where D: Deserializer
|
where D: Deserializer
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_newtype_struct(deserializer).map(TagOrContent::Content)
|
ContentVisitor.visit_newtype_struct(deserializer).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_seq<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
fn visit_seq<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||||
where V: SeqVisitor
|
where V: SeqVisitor
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_seq(visitor).map(TagOrContent::Content)
|
ContentVisitor.visit_seq(visitor).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
fn visit_map<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||||
where V: MapVisitor
|
where V: MapVisitor
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_map(visitor).map(TagOrContent::Content)
|
ContentVisitor.visit_map(visitor).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_enum<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
fn visit_enum<V>(self, visitor: V) -> Result<Self::Value, V::Error>
|
||||||
where V: EnumVisitor
|
where V: EnumVisitor
|
||||||
{
|
{
|
||||||
ContentVisitor::new().visit_enum(visitor).map(TagOrContent::Content)
|
ContentVisitor.visit_enum(visitor).map(TagOrContent::Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used by generated code to deserialize an internally tagged enum.
|
/// Used by generated code to deserialize an internally tagged enum.
|
||||||
///
|
///
|
||||||
/// Not public API.
|
/// Not public API.
|
||||||
pub struct TaggedContent<T, E> {
|
pub struct TaggedContent<T> {
|
||||||
pub tag: T,
|
pub tag: T,
|
||||||
pub content: Content<E>,
|
pub content: Content,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Not public API.
|
/// Not public API.
|
||||||
pub struct TaggedContentVisitor<T, E> {
|
pub struct TaggedContentVisitor<T> {
|
||||||
tag_name: &'static str,
|
tag_name: &'static str,
|
||||||
tag: PhantomData<T>,
|
tag: PhantomData<T>,
|
||||||
err: PhantomData<E>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> TaggedContentVisitor<T, E> {
|
impl<T> TaggedContentVisitor<T> {
|
||||||
/// Visitor for the content of an internally tagged enum with the given tag
|
/// Visitor for the content of an internally tagged enum with the given tag
|
||||||
/// name.
|
/// name.
|
||||||
pub fn new(name: &'static str) -> Self {
|
pub fn new(name: &'static str) -> Self {
|
||||||
TaggedContentVisitor {
|
TaggedContentVisitor {
|
||||||
tag_name: name,
|
tag_name: name,
|
||||||
tag: PhantomData,
|
tag: PhantomData,
|
||||||
err: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> DeserializeSeed for TaggedContentVisitor<T, E>
|
impl<T> DeserializeSeed for TaggedContentVisitor<T>
|
||||||
where T: Deserialize
|
where T: Deserialize
|
||||||
{
|
{
|
||||||
type Value = TaggedContent<T, E>;
|
type Value = TaggedContent<T>;
|
||||||
|
|
||||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||||
where D: Deserializer
|
where D: Deserializer
|
||||||
@@ -476,10 +462,10 @@ impl<T, E> DeserializeSeed for TaggedContentVisitor<T, E>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> Visitor for TaggedContentVisitor<T, E>
|
impl<T> Visitor for TaggedContentVisitor<T>
|
||||||
where T: Deserialize
|
where T: Deserialize
|
||||||
{
|
{
|
||||||
type Value = TaggedContent<T, E>;
|
type Value = TaggedContent<T>;
|
||||||
|
|
||||||
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt.write_str("any value")
|
fmt.write_str("any value")
|
||||||
@@ -518,9 +504,15 @@ impl<T, E> Visitor for TaggedContentVisitor<T, E>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Not public API
|
||||||
|
pub struct ContentDeserializer<E> {
|
||||||
|
content: Content,
|
||||||
|
err: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Used when deserializing an internally tagged enum because the content will
|
/// Used when deserializing an internally tagged enum because the content will
|
||||||
/// be used exactly once.
|
/// be used exactly once.
|
||||||
impl<E> Deserializer for Content<E>
|
impl<E> Deserializer for ContentDeserializer<E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
type Error = E;
|
type Error = E;
|
||||||
@@ -528,8 +520,8 @@ impl<E> Deserializer for Content<E>
|
|||||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where V: Visitor
|
where V: Visitor
|
||||||
{
|
{
|
||||||
match self {
|
match self.content {
|
||||||
Content::Bool(v, _) => visitor.visit_bool(v),
|
Content::Bool(v) => visitor.visit_bool(v),
|
||||||
Content::U8(v) => visitor.visit_u8(v),
|
Content::U8(v) => visitor.visit_u8(v),
|
||||||
Content::U16(v) => visitor.visit_u16(v),
|
Content::U16(v) => visitor.visit_u16(v),
|
||||||
Content::U32(v) => visitor.visit_u32(v),
|
Content::U32(v) => visitor.visit_u32(v),
|
||||||
@@ -544,17 +536,17 @@ impl<E> Deserializer for Content<E>
|
|||||||
Content::String(v) => visitor.visit_string(v),
|
Content::String(v) => visitor.visit_string(v),
|
||||||
Content::Unit => visitor.visit_unit(),
|
Content::Unit => visitor.visit_unit(),
|
||||||
Content::None => visitor.visit_none(),
|
Content::None => visitor.visit_none(),
|
||||||
Content::Some(v) => visitor.visit_some(*v),
|
Content::Some(v) => visitor.visit_some(ContentDeserializer::new(*v)),
|
||||||
Content::Newtype(v) => visitor.visit_newtype_struct(*v),
|
Content::Newtype(v) => visitor.visit_newtype_struct(ContentDeserializer::new(*v)),
|
||||||
Content::Seq(v) => {
|
Content::Seq(v) => {
|
||||||
let seq = v.into_iter();
|
let seq = v.into_iter().map(ContentDeserializer::new);
|
||||||
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
||||||
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
||||||
try!(seq_visitor.end());
|
try!(seq_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
},
|
},
|
||||||
Content::Map(v) => {
|
Content::Map(v) => {
|
||||||
let map = v.into_iter();
|
let map = v.into_iter().map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
|
||||||
let mut map_visitor = de::value::MapDeserializer::new(map);
|
let mut map_visitor = de::value::MapDeserializer::new(map);
|
||||||
let value = try!(visitor.visit_map(&mut map_visitor));
|
let value = try!(visitor.visit_map(&mut map_visitor));
|
||||||
try!(map_visitor.end());
|
try!(map_visitor.end());
|
||||||
@@ -567,9 +559,9 @@ impl<E> Deserializer for Content<E>
|
|||||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where V: Visitor
|
where V: Visitor
|
||||||
{
|
{
|
||||||
match self {
|
match self.content {
|
||||||
Content::None => visitor.visit_none(),
|
Content::None => visitor.visit_none(),
|
||||||
Content::Some(v) => visitor.visit_some(*v),
|
Content::Some(v) => visitor.visit_some(ContentDeserializer::new(*v)),
|
||||||
Content::Unit => visitor.visit_unit(),
|
Content::Unit => visitor.visit_unit(),
|
||||||
_ => visitor.visit_some(self)
|
_ => visitor.visit_some(self)
|
||||||
}
|
}
|
||||||
@@ -588,19 +580,25 @@ impl<E> Deserializer for Content<E>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> de::value::ValueDeserializer<E> for Content<E>
|
impl<E> ContentDeserializer<E> {
|
||||||
where E: de::Error
|
/// private API, don't use
|
||||||
{
|
pub fn new(content: Content) -> Self {
|
||||||
type Deserializer = Self;
|
ContentDeserializer {
|
||||||
|
content: content,
|
||||||
fn into_deserializer(self) -> Self {
|
err: PhantomData,
|
||||||
self
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Not public API.
|
||||||
|
pub struct ContentRefDeserializer<'a, E> {
|
||||||
|
content: &'a Content,
|
||||||
|
err: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Used when deserializing an untagged enum because the content may need to be
|
/// Used when deserializing an untagged enum because the content may need to be
|
||||||
/// used more than once.
|
/// used more than once.
|
||||||
impl<'a, E> Deserializer for &'a Content<E>
|
impl<'a, E> Deserializer for ContentRefDeserializer<'a, E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
type Error = E;
|
type Error = E;
|
||||||
@@ -608,8 +606,8 @@ impl<'a, E> Deserializer for &'a Content<E>
|
|||||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where V: Visitor
|
where V: Visitor
|
||||||
{
|
{
|
||||||
match *self {
|
match *self.content {
|
||||||
Content::Bool(v, _) => visitor.visit_bool(v),
|
Content::Bool(v) => visitor.visit_bool(v),
|
||||||
Content::U8(v) => visitor.visit_u8(v),
|
Content::U8(v) => visitor.visit_u8(v),
|
||||||
Content::U16(v) => visitor.visit_u16(v),
|
Content::U16(v) => visitor.visit_u16(v),
|
||||||
Content::U32(v) => visitor.visit_u32(v),
|
Content::U32(v) => visitor.visit_u32(v),
|
||||||
@@ -624,17 +622,17 @@ impl<'a, E> Deserializer for &'a Content<E>
|
|||||||
Content::String(ref v) => visitor.visit_str(v),
|
Content::String(ref v) => visitor.visit_str(v),
|
||||||
Content::Unit => visitor.visit_unit(),
|
Content::Unit => visitor.visit_unit(),
|
||||||
Content::None => visitor.visit_none(),
|
Content::None => visitor.visit_none(),
|
||||||
Content::Some(ref v) => visitor.visit_some(&**v),
|
Content::Some(ref v) => visitor.visit_some(ContentRefDeserializer::new(v)),
|
||||||
Content::Newtype(ref v) => visitor.visit_newtype_struct(&**v),
|
Content::Newtype(ref v) => visitor.visit_newtype_struct(ContentRefDeserializer::new(v)),
|
||||||
Content::Seq(ref v) => {
|
Content::Seq(ref v) => {
|
||||||
let seq = v.into_iter();
|
let seq = v.into_iter().map(ContentRefDeserializer::new);
|
||||||
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
let mut seq_visitor = de::value::SeqDeserializer::new(seq);
|
||||||
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
let value = try!(visitor.visit_seq(&mut seq_visitor));
|
||||||
try!(seq_visitor.end());
|
try!(seq_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
},
|
},
|
||||||
Content::Map(ref v) => {
|
Content::Map(ref v) => {
|
||||||
let map = v.into_iter().map(|&(ref k, ref v)| (k, 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 mut map_visitor = de::value::MapDeserializer::new(map);
|
||||||
let value = try!(visitor.visit_map(&mut map_visitor));
|
let value = try!(visitor.visit_map(&mut map_visitor));
|
||||||
try!(map_visitor.end());
|
try!(map_visitor.end());
|
||||||
@@ -647,9 +645,9 @@ impl<'a, E> Deserializer for &'a Content<E>
|
|||||||
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where V: Visitor
|
where V: Visitor
|
||||||
{
|
{
|
||||||
match *self {
|
match *self.content {
|
||||||
Content::None => visitor.visit_none(),
|
Content::None => visitor.visit_none(),
|
||||||
Content::Some(ref v) => visitor.visit_some(&**v),
|
Content::Some(ref v) => visitor.visit_some(ContentRefDeserializer::new(v)),
|
||||||
Content::Unit => visitor.visit_unit(),
|
Content::Unit => visitor.visit_unit(),
|
||||||
_ => visitor.visit_some(self)
|
_ => visitor.visit_some(self)
|
||||||
}
|
}
|
||||||
@@ -668,7 +666,27 @@ impl<'a, E> Deserializer for &'a Content<E>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, E> de::value::ValueDeserializer<E> for &'a Content<E>
|
impl<'a, E> ContentRefDeserializer<'a, E> {
|
||||||
|
/// private API, don't use
|
||||||
|
pub fn new(content: &'a Content) -> Self {
|
||||||
|
ContentRefDeserializer {
|
||||||
|
content: content,
|
||||||
|
err: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<E> de::value::ValueDeserializer<E> for ContentDeserializer<E>
|
||||||
|
where E: de::Error
|
||||||
|
{
|
||||||
|
type Deserializer = Self;
|
||||||
|
|
||||||
|
fn into_deserializer(self) -> Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, E> de::value::ValueDeserializer<E> for ContentRefDeserializer<'a, E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
type Deserializer = Self;
|
type Deserializer = Self;
|
||||||
|
|||||||
+1
-1
@@ -859,7 +859,7 @@ pub trait Deserializer: Sized {
|
|||||||
/// benefit from taking ownership of buffered data owned by the
|
/// benefit from taking ownership of buffered data owned by the
|
||||||
/// `Deserializer`.
|
/// `Deserializer`.
|
||||||
///
|
///
|
||||||
/// If the `Visitor would benefit from taking ownership of `Vec<u8>` data,
|
/// If the `Visitor` would benefit from taking ownership of `Vec<u8>` data,
|
||||||
/// indicate this to the `Deserializer` by using `deserialize_byte_buf`
|
/// indicate this to the `Deserializer` by using `deserialize_byte_buf`
|
||||||
/// instead.
|
/// instead.
|
||||||
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ use de::{Deserialize, Deserializer, Error, Visitor};
|
|||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
pub use de::content::{
|
pub use de::content::{
|
||||||
Content,
|
Content,
|
||||||
|
ContentRefDeserializer,
|
||||||
|
ContentDeserializer,
|
||||||
TaggedContentVisitor,
|
TaggedContentVisitor,
|
||||||
InternallyTaggedUnitVisitor,
|
InternallyTaggedUnitVisitor,
|
||||||
UntaggedUnitVisitor,
|
UntaggedUnitVisitor,
|
||||||
|
|||||||
+1
-1
@@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
#![doc(html_root_url="https://docs.serde.rs")]
|
#![doc(html_root_url="https://docs.serde.rs")]
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
#![cfg_attr(feature = "unstable", feature(nonzero, inclusive_range, zero_one))]
|
#![cfg_attr(feature = "unstable", feature(inclusive_range, nonzero, specialization, zero_one))]
|
||||||
#![cfg_attr(feature = "alloc", feature(alloc))]
|
#![cfg_attr(feature = "alloc", feature(alloc))]
|
||||||
#![cfg_attr(feature = "collections", feature(collections))]
|
#![cfg_attr(feature = "collections", feature(collections))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(linkedlist, type_complexity, doc_markdown))]
|
#![cfg_attr(feature = "cargo-clippy", allow(linkedlist, type_complexity, doc_markdown))]
|
||||||
|
|||||||
+9
-60
@@ -63,12 +63,9 @@ use super::{
|
|||||||
SerializeTuple,
|
SerializeTuple,
|
||||||
Serializer,
|
Serializer,
|
||||||
};
|
};
|
||||||
#[cfg(any(feature = "std", feature = "unstable"))]
|
#[cfg(feature = "std")]
|
||||||
use super::Error;
|
use super::Error;
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
use super::Iterator;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! impl_visit {
|
macro_rules! impl_visit {
|
||||||
@@ -147,24 +144,6 @@ impl<T> Serialize for PhantomData<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
impl<T> Serialize for [T]
|
|
||||||
where T: Serialize,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where S: Serializer,
|
|
||||||
{
|
|
||||||
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
|
|
||||||
for e in self {
|
|
||||||
try!(seq.serialize_element(e));
|
|
||||||
}
|
|
||||||
seq.end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! array_impls {
|
macro_rules! array_impls {
|
||||||
@@ -220,48 +199,23 @@ array_impls!(32);
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
impl<'a, I> Serialize for Iterator<I>
|
|
||||||
where I: IntoIterator, <I as IntoIterator>::Item: Serialize
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where S: Serializer,
|
|
||||||
{
|
|
||||||
// FIXME: use specialization to prevent invalidating the object in case of clonable iterators?
|
|
||||||
let iter = match self.data.borrow_mut().take() {
|
|
||||||
Some(iter) => iter.into_iter(),
|
|
||||||
None => return Err(Error::custom("Iterator used twice")),
|
|
||||||
};
|
|
||||||
let size = match iter.size_hint() {
|
|
||||||
(lo, Some(hi)) if lo == hi => Some(lo),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
let mut seq = try!(serializer.serialize_seq(size));
|
|
||||||
for e in iter {
|
|
||||||
try!(seq.serialize_element(&e));
|
|
||||||
}
|
|
||||||
seq.end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
macro_rules! serialize_seq {
|
macro_rules! serialize_seq {
|
||||||
() => {
|
() => {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where S: Serializer,
|
where S: Serializer,
|
||||||
{
|
{
|
||||||
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
|
serializer.collect_seq(self)
|
||||||
for e in self {
|
|
||||||
try!(seq.serialize_element(&e));
|
|
||||||
}
|
|
||||||
seq.end()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Serialize for [T]
|
||||||
|
where T: Serialize,
|
||||||
|
{
|
||||||
|
serialize_seq!();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<T> Serialize for BinaryHeap<T>
|
impl<T> Serialize for BinaryHeap<T>
|
||||||
where T: Serialize + Ord
|
where T: Serialize + Ord
|
||||||
@@ -556,12 +510,7 @@ macro_rules! serialize_map {
|
|||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where S: Serializer,
|
where S: Serializer,
|
||||||
{
|
{
|
||||||
use super::SerializeMap;
|
serializer.collect_map(self)
|
||||||
let mut map = try!(serializer.serialize_map(Some(self.len())));
|
|
||||||
for (k, v) in self {
|
|
||||||
try!(map.serialize_entry(k, v));
|
|
||||||
}
|
|
||||||
map.end()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-23
@@ -98,10 +98,8 @@ use std::error;
|
|||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use error;
|
use error;
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
use core::cell::RefCell;
|
|
||||||
|
|
||||||
use core::fmt::Display;
|
use core::fmt::Display;
|
||||||
|
use core::iter::IntoIterator;
|
||||||
|
|
||||||
mod impls;
|
mod impls;
|
||||||
mod impossible;
|
mod impossible;
|
||||||
@@ -242,7 +240,7 @@ pub trait Serialize {
|
|||||||
/// is the `serde_json::value::Serializer` (distinct from the main `serde_json`
|
/// is the `serde_json::value::Serializer` (distinct from the main `serde_json`
|
||||||
/// serializer) that produces a `serde_json::Value` data structure in memory as
|
/// serializer) that produces a `serde_json::Value` data structure in memory as
|
||||||
/// output.
|
/// output.
|
||||||
pub trait Serializer {
|
pub trait Serializer: Sized {
|
||||||
/// The output type produced by this `Serializer` during successful
|
/// The output type produced by this `Serializer` during successful
|
||||||
/// serialization. Most serializers that produce text or binary output
|
/// serialization. Most serializers that produce text or binary output
|
||||||
/// should set `Ok = ()` and serialize into an `io::Write` or buffer
|
/// should set `Ok = ()` and serialize into an `io::Write` or buffer
|
||||||
@@ -607,6 +605,41 @@ pub trait Serializer {
|
|||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeStructVariant, Self::Error>;
|
) -> Result<Self::SerializeStructVariant, Self::Error>;
|
||||||
|
|
||||||
|
/// Collect an iterator as a sequence.
|
||||||
|
///
|
||||||
|
/// The default implementation serializes each item yielded by the iterator
|
||||||
|
/// using `Self::SerializeSeq`. Implementors should not need to override
|
||||||
|
/// this method.
|
||||||
|
fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>
|
||||||
|
where I: IntoIterator,
|
||||||
|
<I as IntoIterator>::Item: Serialize,
|
||||||
|
{
|
||||||
|
let iter = iter.into_iter();
|
||||||
|
let mut serializer = try!(self.serialize_seq(iter.len_hint()));
|
||||||
|
for item in iter {
|
||||||
|
try!(serializer.serialize_element(&item));
|
||||||
|
}
|
||||||
|
serializer.end()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Collect an iterator as a map.
|
||||||
|
///
|
||||||
|
/// The default implementation serializes each pair yielded by the iterator
|
||||||
|
/// using `Self::SerializeMap`. Implementors should not need to override
|
||||||
|
/// this method.
|
||||||
|
fn collect_map<K, V, I>(self, iter: I) -> Result<Self::Ok, Self::Error>
|
||||||
|
where K: Serialize,
|
||||||
|
V: Serialize,
|
||||||
|
I: IntoIterator<Item = (K, V)>,
|
||||||
|
{
|
||||||
|
let iter = iter.into_iter();
|
||||||
|
let mut serializer = try!(self.serialize_map(iter.len_hint()));
|
||||||
|
for (key, value) in iter {
|
||||||
|
try!(serializer.serialize_entry(&key, &value));
|
||||||
|
}
|
||||||
|
serializer.end()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returned from `Serializer::serialize_seq` and
|
/// Returned from `Serializer::serialize_seq` and
|
||||||
@@ -803,26 +836,32 @@ pub trait SerializeStructVariant {
|
|||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A wrapper type for iterators that implements `Serialize` for iterators whose
|
trait LenHint: Iterator {
|
||||||
/// items implement `Serialize`. Don't use multiple times. Create new versions
|
fn len_hint(&self) -> Option<usize>;
|
||||||
/// of this with the `serde::ser::iterator` function every time you want to
|
|
||||||
/// serialize an iterator.
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
pub struct Iterator<I>
|
|
||||||
where <I as IntoIterator>::Item: Serialize,
|
|
||||||
I: IntoIterator
|
|
||||||
{
|
|
||||||
data: RefCell<Option<I>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a wrapper type that can be passed to any function expecting a
|
impl<I: Iterator> LenHint for I {
|
||||||
/// `Serialize` and will serialize the given iterator as a sequence.
|
#[cfg(not(feature = "unstable"))]
|
||||||
#[cfg(feature = "unstable")]
|
fn len_hint(&self) -> Option<usize> {
|
||||||
pub fn iterator<I>(iter: I) -> Iterator<I>
|
iterator_len_hint(self)
|
||||||
where <I as IntoIterator>::Item: Serialize,
|
}
|
||||||
I: IntoIterator
|
|
||||||
{
|
#[cfg(feature = "unstable")]
|
||||||
Iterator {
|
default fn len_hint(&self) -> Option<usize> {
|
||||||
data: RefCell::new(Some(iter)),
|
iterator_len_hint(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
impl<I: ExactSizeIterator> LenHint for I {
|
||||||
|
fn len_hint(&self) -> Option<usize> {
|
||||||
|
Some(self.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn iterator_len_hint<I: Iterator>(iter: &I) -> Option<usize> {
|
||||||
|
match iter.size_hint() {
|
||||||
|
(lo, Some(hi)) if lo == hi => Some(lo),
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "0.9.6"
|
version = "0.9.7"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
homepage = "https://serde.rs"
|
homepage = "https://serde.rs"
|
||||||
repository = "https://github.com/serde-rs/serde"
|
repository = "https://github.com/serde-rs/serde"
|
||||||
documentation = "https://serde.rs/codegen.html"
|
documentation = "https://serde.rs/codegen.html"
|
||||||
keywords = ["serde", "serialization"]
|
keywords = ["serde", "serialization", "no_std"]
|
||||||
include = ["Cargo.toml", "src/**/*.rs"]
|
include = ["Cargo.toml", "src/**/*.rs"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -704,7 +704,7 @@ fn deserialize_internally_tagged_enum(
|
|||||||
ty.clone(),
|
ty.clone(),
|
||||||
variant,
|
variant,
|
||||||
item_attrs,
|
item_attrs,
|
||||||
quote!(_tagged.content),
|
quote!(_serde::de::private::ContentDeserializer::<__D::Error>::new(_tagged.content)),
|
||||||
);
|
);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
@@ -719,7 +719,7 @@ fn deserialize_internally_tagged_enum(
|
|||||||
|
|
||||||
let _tagged = try!(_serde::Deserializer::deserialize(
|
let _tagged = try!(_serde::Deserializer::deserialize(
|
||||||
deserializer,
|
deserializer,
|
||||||
_serde::de::private::TaggedContentVisitor::<__Field, __D::Error>::new(#tag)));
|
_serde::de::private::TaggedContentVisitor::<__Field>::new(#tag)));
|
||||||
|
|
||||||
match _tagged.tag {
|
match _tagged.tag {
|
||||||
#(#variant_arms)*
|
#(#variant_arms)*
|
||||||
@@ -743,7 +743,7 @@ fn deserialize_untagged_enum(
|
|||||||
ty.clone(),
|
ty.clone(),
|
||||||
variant,
|
variant,
|
||||||
item_attrs,
|
item_attrs,
|
||||||
quote!(&_content),
|
quote!(_serde::de::private::ContentRefDeserializer::<__D::Error>::new(&_content)),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -756,7 +756,7 @@ fn deserialize_untagged_enum(
|
|||||||
let fallthrough_msg = format!("data did not match any variant of untagged enum {}", type_ident);
|
let fallthrough_msg = format!("data did not match any variant of untagged enum {}", type_ident);
|
||||||
|
|
||||||
quote!({
|
quote!({
|
||||||
let _content = try!(<_serde::de::private::Content<__D::Error> as _serde::Deserialize>::deserialize(deserializer));
|
let _content = try!(<_serde::de::private::Content as _serde::Deserialize>::deserialize(deserializer));
|
||||||
|
|
||||||
#(
|
#(
|
||||||
if let _serde::export::Ok(ok) = #attempts {
|
if let _serde::export::Ok(ok) = #attempts {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "0.9.6"
|
version = "0.9.7"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
struct S {
|
struct S {
|
||||||
#[serde(rename="x", serialize="y")] //~^^ HELP: unknown serde field attribute `serialize`
|
#[serde(rename="x", serialize="y")] //~^^ HELP: unknown serde field attribute `serialize`
|
||||||
x: (),
|
x: (),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
struct S {
|
struct S {
|
||||||
#[serde(rename="x")]
|
#[serde(rename="x")]
|
||||||
#[serde(rename(deserialize="y"))] //~^^^ HELP: duplicate serde attribute `rename`
|
#[serde(rename(deserialize="y"))] //~^^^ HELP: duplicate serde attribute `rename`
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
struct S {
|
struct S {
|
||||||
#[serde(rename(serialize="x"), rename(serialize="y"))] //~^^ HELP: duplicate serde attribute `rename`
|
#[serde(rename(serialize="x"), rename(serialize="y"))] //~^^ HELP: duplicate serde attribute `rename`
|
||||||
x: (),
|
x: (),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
struct S {
|
struct S {
|
||||||
#[serde(rename(serialize="x"))]
|
#[serde(rename(serialize="x"))]
|
||||||
#[serde(rename="y")] //~^^^ HELP: duplicate serde attribute `rename`
|
#[serde(rename="y")] //~^^^ HELP: duplicate serde attribute `rename`
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
struct S {
|
struct S {
|
||||||
#[serde(rename(serialize="x", serialize="y"))] //~^^ HELP: duplicate serde attribute `rename`
|
#[serde(rename(serialize="x", serialize="y"))] //~^^ HELP: duplicate serde attribute `rename`
|
||||||
x: (),
|
x: (),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
struct S {
|
struct S {
|
||||||
#[serde(rename(serialize="x"))]
|
#[serde(rename(serialize="x"))]
|
||||||
#[serde(rename(serialize="y"))] //~^^^ HELP: duplicate serde attribute `rename`
|
#[serde(rename(serialize="y"))] //~^^^ HELP: duplicate serde attribute `rename`
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
#[serde(tag = "type")] //~^ HELP: #[serde(tag = "...")] cannot be used with tuple variants
|
#[serde(tag = "type")] //~^ HELP: #[serde(tag = "...")] cannot be used with tuple variants
|
||||||
enum E {
|
enum E {
|
||||||
Tuple(u8, u8),
|
Tuple(u8, u8),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
#[serde(tag = "type")] //~^ HELP: #[serde(tag = "...")] can only be used on enums
|
#[serde(tag = "type")] //~^ HELP: #[serde(tag = "...")] can only be used on enums
|
||||||
struct S;
|
struct S;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
#[serde(tag = "type")] //~^^ HELP: enum cannot be both untagged and internally tagged
|
#[serde(tag = "type")] //~^^ HELP: enum cannot be both untagged and internally tagged
|
||||||
enum E {
|
enum E {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
#[serde(untagged)] //~^ HELP: #[serde(untagged)] can only be used on enums
|
#[serde(untagged)] //~^ HELP: #[serde(untagged)] can only be used on enums
|
||||||
struct S;
|
struct S;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize, Deserialize)] //~ ERROR: proc-macro derive panicked
|
||||||
struct Test<'a> {
|
struct Test<'a> {
|
||||||
s: &'a str, //~^^ HELP: Serde does not support deserializing fields of type &str
|
s: &'a str, //~^^ HELP: Serde does not support deserializing fields of type &str
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
#[serde(abc="xyz")] //~^ HELP: unknown serde container attribute `abc`
|
#[serde(abc="xyz")] //~^ HELP: unknown serde container attribute `abc`
|
||||||
struct A {
|
struct A {
|
||||||
x: u32,
|
x: u32,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
struct C {
|
struct C {
|
||||||
#[serde(abc="xyz")] //~^^ HELP: unknown serde field attribute `abc`
|
#[serde(abc="xyz")] //~^^ HELP: unknown serde field attribute `abc`
|
||||||
x: u32,
|
x: u32,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
#[derive(Serialize)] //~ ERROR: proc-macro derive panicked
|
||||||
enum E {
|
enum E {
|
||||||
#[serde(abc="xyz")] //~^^ HELP: unknown serde variant attribute `abc`
|
#[serde(abc="xyz")] //~^^ HELP: unknown serde variant attribute `abc`
|
||||||
V,
|
V,
|
||||||
|
|||||||
Reference in New Issue
Block a user