mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 06:57:56 +00:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a09f05644 | |||
| 5923a0cd2f | |||
| 1576b5a8a0 | |||
| 2c4dbf5a84 | |||
| 021f4f2d70 | |||
| decc571988 | |||
| 322d7a90db | |||
| dd3f653103 | |||
| 46a1860601 | |||
| 84a573c926 | |||
| 7dfa8f43f4 | |||
| 7375b4e847 | |||
| 48da62ed07 | |||
| 9834af7ed9 | |||
| 6b404d8529 | |||
| 3119cc8857 | |||
| bb059b97c0 | |||
| b7188f7022 | |||
| a64fe99d1b | |||
| c716c4e261 | |||
| 3d2e3beafe | |||
| 1917e54a6e | |||
| 898b346d48 | |||
| e90adb20ef | |||
| a52e7f5554 | |||
| 7afb8b52ae | |||
| cb4694387e |
+5
-2
@@ -3,7 +3,8 @@ rust:
|
|||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
- 1.5.0
|
- 1.7.0
|
||||||
|
- 1.8.0
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
@@ -18,7 +19,7 @@ script:
|
|||||||
- (cd serde && travis-cargo build)
|
- (cd serde && travis-cargo build)
|
||||||
- (cd serde && travis-cargo test)
|
- (cd serde && travis-cargo test)
|
||||||
- (cd serde && travis-cargo --only nightly test -- --features nightly-testing)
|
- (cd serde && travis-cargo --only nightly test -- --features nightly-testing)
|
||||||
- (cd serde && travis-cargo --skip 1.5.0 build -- --no-default-features)
|
- (cd serde && travis-cargo build -- --no-default-features)
|
||||||
- (cd serde && travis-cargo --only nightly build -- --no-default-features)
|
- (cd serde && travis-cargo --only nightly build -- --no-default-features)
|
||||||
- (cd serde && travis-cargo --only nightly build -- --no-default-features --features alloc)
|
- (cd serde && travis-cargo --only nightly build -- --no-default-features --features alloc)
|
||||||
- (cd serde && travis-cargo --only nightly build -- --no-default-features --features collections)
|
- (cd serde && travis-cargo --only nightly build -- --no-default-features --features collections)
|
||||||
@@ -26,6 +27,8 @@ script:
|
|||||||
- (cd serde_tests && travis-cargo --only nightly test -- --features nightly-testing)
|
- (cd serde_tests && travis-cargo --only nightly test -- --features nightly-testing)
|
||||||
- (cd serde_macros && travis-cargo --only nightly test -- --features nightly-testing)
|
- (cd serde_macros && travis-cargo --only nightly test -- --features nightly-testing)
|
||||||
- (cd serde_macros && travis-cargo --only nightly bench -- --features nightly-testing)
|
- (cd serde_macros && travis-cargo --only nightly bench -- --features nightly-testing)
|
||||||
|
- (cd examples/serde-syntex-example && travis-cargo run)
|
||||||
|
- (cd examples/serde-syntex-example && travis-cargo --only nightly run -- --features nightly --no-default-features)
|
||||||
- (cd serde && travis-cargo --only stable doc)
|
- (cd serde && travis-cargo --only stable doc)
|
||||||
- (cd serde_codegen && travis-cargo --only stable doc)
|
- (cd serde_codegen && travis-cargo --only stable doc)
|
||||||
- (cd serde_macros && travis-cargo --only nightly doc)
|
- (cd serde_macros && travis-cargo --only nightly doc)
|
||||||
|
|||||||
@@ -142,10 +142,7 @@ pub fn main() {
|
|||||||
let src = Path::new("src/main.rs.in");
|
let src = Path::new("src/main.rs.in");
|
||||||
let dst = Path::new(&out_dir).join("main.rs");
|
let dst = Path::new(&out_dir).join("main.rs");
|
||||||
|
|
||||||
let mut registry = syntex::Registry::new();
|
serde_codegen::expand(&src, &dst).unwrap();
|
||||||
|
|
||||||
serde_codegen::register(&mut registry);
|
|
||||||
registry.expand("", &src, &dst).unwrap();
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -203,10 +200,7 @@ mod inner {
|
|||||||
let src = Path::new("src/main.rs.in");
|
let src = Path::new("src/main.rs.in");
|
||||||
let dst = Path::new(&out_dir).join("main.rs");
|
let dst = Path::new(&out_dir).join("main.rs");
|
||||||
|
|
||||||
let mut registry = syntex::Registry::new();
|
serde_codegen::expand(&src, &dst).unwrap();
|
||||||
|
|
||||||
serde_codegen::register(&mut registry);
|
|
||||||
registry.expand("", &src, &dst).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
paths = [
|
||||||
|
"../serde",
|
||||||
|
"../serde_codegen",
|
||||||
|
"../serde_macros",
|
||||||
|
]
|
||||||
@@ -9,10 +9,10 @@ default = ["serde_codegen"]
|
|||||||
nightly = ["serde_macros"]
|
nightly = ["serde_macros"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
serde_codegen = { version = "^0.7.8", optional = true }
|
serde_codegen = { version = "^0.7.10", optional = true }
|
||||||
syntex = "^0.33.0"
|
syntex = "^0.33.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "^0.7.8"
|
serde = "^0.7.10"
|
||||||
serde_json = "^0.7.0"
|
serde_json = "^0.7.0"
|
||||||
serde_macros = { version = "^0.7.8", optional = true }
|
serde_macros = { version = "^0.7.10", optional = true }
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ This example demonstrates how to use Serde with Syntex. On stable or nightly
|
|||||||
with Syntex, it can be built with:
|
with Syntex, it can be built with:
|
||||||
|
|
||||||
```
|
```
|
||||||
% multirust run stable cargo run
|
% rustup run stable cargo run
|
||||||
Running `target/debug/serde-syntex-example`
|
Running `target/debug/serde-syntex-example`
|
||||||
{"x":1,"y":2}
|
{"x":1,"y":2}
|
||||||
Point { x: 1, y: 2 }
|
Point { x: 1, y: 2 }
|
||||||
|
|
||||||
% multirust run nightly cargo run
|
% rustup run nightly cargo run
|
||||||
Running `target/debug/serde-syntex-example`
|
Running `target/debug/serde-syntex-example`
|
||||||
{"x":1,"y":2}
|
{"x":1,"y":2}
|
||||||
Point { x: 1, y: 2 }
|
Point { x: 1, y: 2 }
|
||||||
@@ -16,5 +16,5 @@ Point { x: 1, y: 2 }
|
|||||||
On nightly, it can use a plugin with:
|
On nightly, it can use a plugin with:
|
||||||
|
|
||||||
```
|
```
|
||||||
% multirust run nightly cargo run --features nightly --no-default-features
|
% rustup run nightly cargo run --features nightly --no-default-features
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ mod inner {
|
|||||||
let src = Path::new("src/main.rs.in");
|
let src = Path::new("src/main.rs.in");
|
||||||
let dst = Path::new(&out_dir).join("main.rs");
|
let dst = Path::new(&out_dir).join("main.rs");
|
||||||
|
|
||||||
let mut registry = syntex::Registry::new();
|
serde_codegen::expand(&src, &dst).unwrap();
|
||||||
|
|
||||||
serde_codegen::register(&mut registry);
|
|
||||||
registry.expand("", &src, &dst).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#![cfg_attr(nightly, feature(custom_derive, plugin))]
|
#![cfg_attr(feature = "serde_macros", feature(custom_derive, plugin))]
|
||||||
#![cfg_attr(nightly, plugin(serde_macros))]
|
#![cfg_attr(feature = "serde_macros", plugin(serde_macros))]
|
||||||
|
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "0.7.8"
|
version = "0.7.10"
|
||||||
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"
|
||||||
|
|||||||
+46
-54
@@ -32,7 +32,7 @@ use collections::enum_set::{CLike, EnumSet};
|
|||||||
#[cfg(all(feature = "nightly", feature = "collections"))]
|
#[cfg(all(feature = "nightly", feature = "collections"))]
|
||||||
use collections::borrow::ToOwned;
|
use collections::borrow::ToOwned;
|
||||||
|
|
||||||
use core::hash::Hash;
|
use core::hash::{Hash, BuildHasher};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::net;
|
use std::net;
|
||||||
@@ -381,29 +381,30 @@ impl<T> Deserialize for PhantomData<T> where T: Deserialize {
|
|||||||
macro_rules! seq_impl {
|
macro_rules! seq_impl {
|
||||||
(
|
(
|
||||||
$ty:ty,
|
$ty:ty,
|
||||||
< $($constraints:ident),* >,
|
$visitor_ty:ident < $($typaram:ident : $bound1:ident $(+ $bound2:ident)*),* >,
|
||||||
$visitor_name:ident,
|
|
||||||
$visitor:ident,
|
$visitor:ident,
|
||||||
$ctor:expr,
|
$ctor:expr,
|
||||||
$with_capacity:expr,
|
$with_capacity:expr,
|
||||||
$insert:expr
|
$insert:expr
|
||||||
) => {
|
) => {
|
||||||
/// A visitor that produces a sequence.
|
/// A visitor that produces a sequence.
|
||||||
pub struct $visitor_name<T> {
|
pub struct $visitor_ty<$($typaram),*> {
|
||||||
marker: PhantomData<T>,
|
marker: PhantomData<$ty>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> $visitor_name<T> {
|
impl<$($typaram),*> $visitor_ty<$($typaram),*>
|
||||||
|
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||||
|
{
|
||||||
/// Construct a new sequence visitor.
|
/// Construct a new sequence visitor.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
$visitor_name {
|
$visitor_ty {
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Visitor for $visitor_name<T>
|
impl<$($typaram),*> Visitor for $visitor_ty<$($typaram),*>
|
||||||
where T: $($constraints +)*,
|
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||||
{
|
{
|
||||||
type Value = $ty;
|
type Value = $ty;
|
||||||
|
|
||||||
@@ -430,13 +431,13 @@ macro_rules! seq_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Deserialize for $ty
|
impl<$($typaram),*> Deserialize for $ty
|
||||||
where T: $($constraints +)*,
|
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||||
{
|
{
|
||||||
fn deserialize<D>(deserializer: &mut D) -> Result<$ty, D::Error>
|
fn deserialize<D>(deserializer: &mut D) -> Result<$ty, D::Error>
|
||||||
where D: Deserializer,
|
where D: Deserializer,
|
||||||
{
|
{
|
||||||
deserializer.deserialize_seq($visitor_name::new())
|
deserializer.deserialize_seq($visitor_ty::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,8 +446,7 @@ macro_rules! seq_impl {
|
|||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
seq_impl!(
|
seq_impl!(
|
||||||
BinaryHeap<T>,
|
BinaryHeap<T>,
|
||||||
<Deserialize, Ord>,
|
BinaryHeapVisitor<T: Deserialize + Ord>,
|
||||||
BinaryHeapVisitor,
|
|
||||||
visitor,
|
visitor,
|
||||||
BinaryHeap::new(),
|
BinaryHeap::new(),
|
||||||
BinaryHeap::with_capacity(visitor.size_hint().0),
|
BinaryHeap::with_capacity(visitor.size_hint().0),
|
||||||
@@ -455,8 +455,7 @@ seq_impl!(
|
|||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
seq_impl!(
|
seq_impl!(
|
||||||
BTreeSet<T>,
|
BTreeSet<T>,
|
||||||
<Deserialize, Eq, Ord>,
|
BTreeSetVisitor<T: Deserialize + Eq + Ord>,
|
||||||
BTreeSetVisitor,
|
|
||||||
visitor,
|
visitor,
|
||||||
BTreeSet::new(),
|
BTreeSet::new(),
|
||||||
BTreeSet::new(),
|
BTreeSet::new(),
|
||||||
@@ -465,8 +464,7 @@ seq_impl!(
|
|||||||
#[cfg(all(feature = "nightly", feature = "collections"))]
|
#[cfg(all(feature = "nightly", feature = "collections"))]
|
||||||
seq_impl!(
|
seq_impl!(
|
||||||
EnumSet<T>,
|
EnumSet<T>,
|
||||||
<Deserialize, CLike>,
|
EnumSetVisitor<T: Deserialize + CLike>,
|
||||||
EnumSetVisitor,
|
|
||||||
visitor,
|
visitor,
|
||||||
EnumSet::new(),
|
EnumSet::new(),
|
||||||
EnumSet::new(),
|
EnumSet::new(),
|
||||||
@@ -475,8 +473,7 @@ seq_impl!(
|
|||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
seq_impl!(
|
seq_impl!(
|
||||||
LinkedList<T>,
|
LinkedList<T>,
|
||||||
<Deserialize>,
|
LinkedListVisitor<T: Deserialize>,
|
||||||
LinkedListVisitor,
|
|
||||||
visitor,
|
visitor,
|
||||||
LinkedList::new(),
|
LinkedList::new(),
|
||||||
LinkedList::new(),
|
LinkedList::new(),
|
||||||
@@ -484,19 +481,18 @@ seq_impl!(
|
|||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
seq_impl!(
|
seq_impl!(
|
||||||
HashSet<T>,
|
HashSet<T, S>,
|
||||||
<Deserialize, Eq, Hash>,
|
HashSetVisitor<T: Deserialize + Eq + Hash,
|
||||||
HashSetVisitor,
|
S: BuildHasher + Default>,
|
||||||
visitor,
|
visitor,
|
||||||
HashSet::new(),
|
HashSet::with_hasher(S::default()),
|
||||||
HashSet::with_capacity(visitor.size_hint().0),
|
HashSet::with_capacity_and_hasher(visitor.size_hint().0, S::default()),
|
||||||
HashSet::insert);
|
HashSet::insert);
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
seq_impl!(
|
seq_impl!(
|
||||||
Vec<T>,
|
Vec<T>,
|
||||||
<Deserialize>,
|
VecVisitor<T: Deserialize>,
|
||||||
VecVisitor,
|
|
||||||
visitor,
|
visitor,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
Vec::with_capacity(visitor.size_hint().0),
|
Vec::with_capacity(visitor.size_hint().0),
|
||||||
@@ -505,8 +501,7 @@ seq_impl!(
|
|||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
seq_impl!(
|
seq_impl!(
|
||||||
VecDeque<T>,
|
VecDeque<T>,
|
||||||
<Deserialize>,
|
VecDequeVisitor<T: Deserialize>,
|
||||||
VecDequeVisitor,
|
|
||||||
visitor,
|
visitor,
|
||||||
VecDeque::new(),
|
VecDeque::new(),
|
||||||
VecDeque::with_capacity(visitor.size_hint().0),
|
VecDeque::with_capacity(visitor.size_hint().0),
|
||||||
@@ -726,30 +721,29 @@ tuple_impls! {
|
|||||||
macro_rules! map_impl {
|
macro_rules! map_impl {
|
||||||
(
|
(
|
||||||
$ty:ty,
|
$ty:ty,
|
||||||
< $($constraints:ident),* >,
|
$visitor_ty:ident < $($typaram:ident : $bound1:ident $(+ $bound2:ident)*),* >,
|
||||||
$visitor_name:ident,
|
|
||||||
$visitor:ident,
|
$visitor:ident,
|
||||||
$ctor:expr,
|
$ctor:expr,
|
||||||
$with_capacity:expr,
|
$with_capacity:expr
|
||||||
$insert:expr
|
|
||||||
) => {
|
) => {
|
||||||
/// A visitor that produces a map.
|
/// A visitor that produces a map.
|
||||||
pub struct $visitor_name<K, V> {
|
pub struct $visitor_ty<$($typaram),*> {
|
||||||
marker: PhantomData<$ty>,
|
marker: PhantomData<$ty>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K, V> $visitor_name<K, V> {
|
impl<$($typaram),*> $visitor_ty<$($typaram),*>
|
||||||
|
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||||
|
{
|
||||||
/// Construct a `MapVisitor*<T>`.
|
/// Construct a `MapVisitor*<T>`.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
$visitor_name {
|
$visitor_ty {
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K, V> Visitor for $visitor_name<K, V>
|
impl<$($typaram),*> Visitor for $visitor_ty<$($typaram),*>
|
||||||
where K: $($constraints +)*,
|
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||||
V: Deserialize,
|
|
||||||
{
|
{
|
||||||
type Value = $ty;
|
type Value = $ty;
|
||||||
|
|
||||||
@@ -767,7 +761,7 @@ macro_rules! map_impl {
|
|||||||
let mut values = $with_capacity;
|
let mut values = $with_capacity;
|
||||||
|
|
||||||
while let Some((key, value)) = try!($visitor.visit()) {
|
while let Some((key, value)) = try!($visitor.visit()) {
|
||||||
$insert(&mut values, key, value);
|
values.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
try!($visitor.end());
|
try!($visitor.end());
|
||||||
@@ -776,14 +770,13 @@ macro_rules! map_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K, V> Deserialize for $ty
|
impl<$($typaram),*> Deserialize for $ty
|
||||||
where K: $($constraints +)*,
|
where $($typaram: $bound1 $(+ $bound2)*),*
|
||||||
V: Deserialize,
|
|
||||||
{
|
{
|
||||||
fn deserialize<D>(deserializer: &mut D) -> Result<$ty, D::Error>
|
fn deserialize<D>(deserializer: &mut D) -> Result<$ty, D::Error>
|
||||||
where D: Deserializer,
|
where D: Deserializer,
|
||||||
{
|
{
|
||||||
deserializer.deserialize_map($visitor_name::new())
|
deserializer.deserialize_map($visitor_ty::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -792,22 +785,21 @@ macro_rules! map_impl {
|
|||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
map_impl!(
|
map_impl!(
|
||||||
BTreeMap<K, V>,
|
BTreeMap<K, V>,
|
||||||
<Deserialize, Eq, Ord>,
|
BTreeMapVisitor<K: Deserialize + Eq + Ord,
|
||||||
BTreeMapVisitor,
|
V: Deserialize>,
|
||||||
visitor,
|
visitor,
|
||||||
BTreeMap::new(),
|
BTreeMap::new(),
|
||||||
BTreeMap::new(),
|
BTreeMap::new());
|
||||||
BTreeMap::insert);
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
map_impl!(
|
map_impl!(
|
||||||
HashMap<K, V>,
|
HashMap<K, V, S>,
|
||||||
<Deserialize, Eq, Hash>,
|
HashMapVisitor<K: Deserialize + Eq + Hash,
|
||||||
HashMapVisitor,
|
V: Deserialize,
|
||||||
|
S: BuildHasher + Default>,
|
||||||
visitor,
|
visitor,
|
||||||
HashMap::new(),
|
HashMap::with_hasher(S::default()),
|
||||||
HashMap::with_capacity(visitor.size_hint().0),
|
HashMap::with_capacity_and_hasher(visitor.size_hint().0, S::default()));
|
||||||
HashMap::insert);
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ use collections::enum_set::{CLike, EnumSet};
|
|||||||
#[cfg(all(feature = "nightly", feature = "collections"))]
|
#[cfg(all(feature = "nightly", feature = "collections"))]
|
||||||
use collections::borrow::ToOwned;
|
use collections::borrow::ToOwned;
|
||||||
|
|
||||||
use core::hash::Hash;
|
use core::hash::{Hash, BuildHasher};
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
use core::iter;
|
use core::iter;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@@ -330,8 +330,9 @@ impl<T> Serialize for EnumSet<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<T> Serialize for HashSet<T>
|
impl<T, H> Serialize for HashSet<T, H>
|
||||||
where T: Serialize + Eq + Hash,
|
where T: Serialize + Eq + Hash,
|
||||||
|
H: BuildHasher,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
@@ -651,9 +652,10 @@ impl<K, V> Serialize for BTreeMap<K, V>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<K, V> Serialize for HashMap<K, V>
|
impl<K, V, H> Serialize for HashMap<K, V, H>
|
||||||
where K: Serialize + Eq + Hash,
|
where K: Serialize + Eq + Hash,
|
||||||
V: Serialize,
|
V: Serialize,
|
||||||
|
H: BuildHasher,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen"
|
name = "serde_codegen"
|
||||||
version = "0.7.8"
|
version = "0.7.10"
|
||||||
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 to auto-generate implementations for the serde framework"
|
description = "Macros to auto-generate implementations for the serde framework"
|
||||||
@@ -17,13 +17,13 @@ nightly-testing = ["clippy"]
|
|||||||
with-syntex = ["quasi/with-syntex", "quasi_codegen", "quasi_codegen/with-syntex", "syntex", "syntex_syntax"]
|
with-syntex = ["quasi/with-syntex", "quasi_codegen", "quasi_codegen/with-syntex", "syntex", "syntex_syntax"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
quasi_codegen = { version = "^0.11.0", optional = true }
|
quasi_codegen = { version = "^0.12.0", optional = true }
|
||||||
syntex = { version = "^0.33.0", optional = true }
|
syntex = { version = "^0.33.0", optional = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
aster = { version = "^0.17.0", default-features = false }
|
aster = { version = "^0.18.0", default-features = false }
|
||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
quasi = { version = "^0.11.0", default-features = false }
|
quasi = { version = "^0.12.0", default-features = false }
|
||||||
quasi_macros = { version = "^0.11.0", optional = true }
|
quasi_macros = { version = "^0.12.0", optional = true }
|
||||||
syntex = { version = "^0.33.0", optional = true }
|
syntex = { version = "^0.35.0", optional = true }
|
||||||
syntex_syntax = { version = "^0.33.0", optional = true }
|
syntex_syntax = { version = "^0.35.0", optional = true }
|
||||||
|
|||||||
@@ -8,13 +8,11 @@ mod inner {
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
let mut registry = syntex::Registry::new();
|
|
||||||
quasi_codegen::register(&mut registry);
|
|
||||||
|
|
||||||
let src = Path::new("src/lib.rs.in");
|
let src = Path::new("src/lib.rs.in");
|
||||||
let dst = Path::new(&out_dir).join("lib.rs");
|
let dst = Path::new(&out_dir).join("lib.rs");
|
||||||
|
|
||||||
registry.expand("", &src, &dst).unwrap();
|
quasi_codegen::expand(&src, &dst).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-22
@@ -212,13 +212,24 @@ pub struct FieldAttrs {
|
|||||||
skip_serializing_field: bool,
|
skip_serializing_field: bool,
|
||||||
skip_deserializing_field: bool,
|
skip_deserializing_field: bool,
|
||||||
skip_serializing_if: Option<ast::Path>,
|
skip_serializing_if: Option<ast::Path>,
|
||||||
default_expr_if_missing: Option<P<ast::Expr>>,
|
default: FieldDefault,
|
||||||
serialize_with: Option<ast::Path>,
|
serialize_with: Option<ast::Path>,
|
||||||
deserialize_with: Option<ast::Path>,
|
deserialize_with: Option<ast::Path>,
|
||||||
ser_bound: Option<Vec<ast::WherePredicate>>,
|
ser_bound: Option<Vec<ast::WherePredicate>>,
|
||||||
de_bound: Option<Vec<ast::WherePredicate>>,
|
de_bound: Option<Vec<ast::WherePredicate>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents the default to use for a field when deserializing.
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum FieldDefault {
|
||||||
|
/// Field must always be specified because it does not have a default.
|
||||||
|
None,
|
||||||
|
/// The default is given by `std::default::Default::default()`.
|
||||||
|
Default,
|
||||||
|
/// The default is given by this function.
|
||||||
|
Path(ast::Path),
|
||||||
|
}
|
||||||
|
|
||||||
impl FieldAttrs {
|
impl FieldAttrs {
|
||||||
/// Extract out the `#[serde(...)]` attributes from a struct field.
|
/// Extract out the `#[serde(...)]` attributes from a struct field.
|
||||||
pub fn from_field(cx: &ExtCtxt,
|
pub fn from_field(cx: &ExtCtxt,
|
||||||
@@ -236,7 +247,7 @@ impl FieldAttrs {
|
|||||||
skip_serializing_field: false,
|
skip_serializing_field: false,
|
||||||
skip_deserializing_field: false,
|
skip_deserializing_field: false,
|
||||||
skip_serializing_if: None,
|
skip_serializing_if: None,
|
||||||
default_expr_if_missing: None,
|
default: FieldDefault::None,
|
||||||
serialize_with: None,
|
serialize_with: None,
|
||||||
deserialize_with: None,
|
deserialize_with: None,
|
||||||
ser_bound: None,
|
ser_bound: None,
|
||||||
@@ -266,17 +277,13 @@ impl FieldAttrs {
|
|||||||
|
|
||||||
// Parse `#[serde(default)]`
|
// Parse `#[serde(default)]`
|
||||||
ast::MetaItemKind::Word(ref name) if name == &"default" => {
|
ast::MetaItemKind::Word(ref name) if name == &"default" => {
|
||||||
let default_expr = builder.expr().default();
|
field_attrs.default = FieldDefault::Default;
|
||||||
field_attrs.default_expr_if_missing = Some(default_expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(default="...")]`
|
// Parse `#[serde(default="...")]`
|
||||||
ast::MetaItemKind::NameValue(ref name, ref lit) if name == &"default" => {
|
ast::MetaItemKind::NameValue(ref name, ref lit) if name == &"default" => {
|
||||||
let wrapped_expr = wrap_default(
|
let path = try!(parse_lit_into_path(cx, name, lit));
|
||||||
try!(parse_lit_into_path(cx, name, lit)),
|
field_attrs.default = FieldDefault::Path(path);
|
||||||
);
|
|
||||||
|
|
||||||
field_attrs.default_expr_if_missing = Some(wrapped_expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip_serializing)]`
|
// Parse `#[serde(skip_serializing)]`
|
||||||
@@ -290,9 +297,8 @@ impl FieldAttrs {
|
|||||||
|
|
||||||
// Initialize field to Default::default() unless a different
|
// Initialize field to Default::default() unless a different
|
||||||
// default is specified by `#[serde(default="...")]`
|
// default is specified by `#[serde(default="...")]`
|
||||||
if field_attrs.default_expr_if_missing.is_none() {
|
if field_attrs.default == FieldDefault::None {
|
||||||
let default_expr = builder.expr().default();
|
field_attrs.default = FieldDefault::Default;
|
||||||
field_attrs.default_expr_if_missing = Some(default_expr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,8 +369,8 @@ impl FieldAttrs {
|
|||||||
self.skip_serializing_if.as_ref()
|
self.skip_serializing_if.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_expr_if_missing(&self) -> Option<&P<ast::Expr>> {
|
pub fn default(&self) -> &FieldDefault {
|
||||||
self.default_expr_if_missing.as_ref()
|
&self.default
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize_with(&self) -> Option<&ast::Path> {
|
pub fn serialize_with(&self) -> Option<&ast::Path> {
|
||||||
@@ -584,11 +590,3 @@ fn parse_lit_into_where(cx: &ExtCtxt, name: &str, lit: &ast::Lit) -> Result<Vec<
|
|||||||
Ok(where_clause.predicates)
|
Ok(where_clause.predicates)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function wraps the expression in `#[serde(default="...")]` in a function to prevent it
|
|
||||||
/// from accessing the internal `Deserialize` state.
|
|
||||||
fn wrap_default(path: ast::Path) -> P<ast::Expr> {
|
|
||||||
AstBuilder::new().expr().call()
|
|
||||||
.build_path(path)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -60,13 +60,13 @@ pub fn with_bound<F>(
|
|||||||
filter: F,
|
filter: F,
|
||||||
bound: &ast::Path,
|
bound: &ast::Path,
|
||||||
) -> Result<ast::Generics, Error>
|
) -> Result<ast::Generics, Error>
|
||||||
where F: Fn(&ast::StructField, &attr::FieldAttrs) -> bool,
|
where F: Fn(&attr::FieldAttrs) -> bool,
|
||||||
{
|
{
|
||||||
Ok(builder.from_generics(generics.clone())
|
Ok(builder.from_generics(generics.clone())
|
||||||
.with_predicates(
|
.with_predicates(
|
||||||
try!(all_fields_with_attrs(cx, item))
|
try!(all_fields_with_attrs(cx, item))
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(ref field, ref attrs)| filter(field, attrs))
|
.filter(|&&(_, ref attrs)| filter(attrs))
|
||||||
.map(|&(ref field, _)| &field.ty)
|
.map(|&(ref field, _)| &field.ty)
|
||||||
// TODO this filter can be removed later, see comment on function
|
// TODO this filter can be removed later, see comment on function
|
||||||
.filter(|ty| contains_generic(ty, generics))
|
.filter(|ty| contains_generic(ty, generics))
|
||||||
|
|||||||
+12
-18
@@ -134,7 +134,7 @@ fn build_impl_generics(
|
|||||||
// deserialized by us so we do not generate a bound. Fields with a `bound`
|
// deserialized by us so we do not generate a bound. Fields with a `bound`
|
||||||
// attribute specify their own bound so we do not generate one. All other fields
|
// attribute specify their own bound so we do not generate one. All other fields
|
||||||
// may need a `T: Deserialize` bound where T is the type of the field.
|
// may need a `T: Deserialize` bound where T is the type of the field.
|
||||||
fn needs_deserialize_bound(_: &ast::StructField, attrs: &attr::FieldAttrs) -> bool {
|
fn needs_deserialize_bound(attrs: &attr::FieldAttrs) -> bool {
|
||||||
!attrs.skip_deserializing_field()
|
!attrs.skip_deserializing_field()
|
||||||
&& attrs.deserialize_with().is_none()
|
&& attrs.deserialize_with().is_none()
|
||||||
&& attrs.de_bound().is_none()
|
&& attrs.de_bound().is_none()
|
||||||
@@ -142,21 +142,8 @@ fn needs_deserialize_bound(_: &ast::StructField, attrs: &attr::FieldAttrs) -> bo
|
|||||||
|
|
||||||
// Fields with a `default` attribute (not `default=...`), and fields with a
|
// Fields with a `default` attribute (not `default=...`), and fields with a
|
||||||
// `skip_deserializing` attribute that do not also have `default=...`.
|
// `skip_deserializing` attribute that do not also have `default=...`.
|
||||||
fn requires_default(field: &ast::StructField, attrs: &attr::FieldAttrs) -> bool {
|
fn requires_default(attrs: &attr::FieldAttrs) -> bool {
|
||||||
for meta_items in field.attrs.iter().filter_map(attr::get_serde_meta_items) {
|
attrs.default() == &attr::FieldDefault::Default
|
||||||
for meta_item in meta_items {
|
|
||||||
match meta_item.node {
|
|
||||||
ast::MetaItemKind::Word(ref name) if name == &"default" => {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
ast::MetaItemKind::NameValue(ref name, _) if name == &"default" => {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attrs.skip_deserializing_field()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_body(
|
fn deserialize_body(
|
||||||
@@ -1234,9 +1221,16 @@ fn expr_is_missing(
|
|||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
attrs: &attr::FieldAttrs,
|
attrs: &attr::FieldAttrs,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
if let Some(expr) = attrs.default_expr_if_missing() {
|
match *attrs.default() {
|
||||||
return expr.clone();
|
attr::FieldDefault::Default => {
|
||||||
|
return quote_expr!(cx, ::std::default::Default::default());
|
||||||
|
}
|
||||||
|
attr::FieldDefault::Path(ref path) => {
|
||||||
|
return quote_expr!(cx, $path());
|
||||||
|
}
|
||||||
|
attr::FieldDefault::None => { /* below */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = attrs.name().deserialize_name_expr();
|
let name = attrs.name().deserialize_name_expr();
|
||||||
match attrs.deserialize_with() {
|
match attrs.deserialize_with() {
|
||||||
None => {
|
None => {
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ extern crate syntax;
|
|||||||
#[cfg(not(feature = "with-syntex"))]
|
#[cfg(not(feature = "with-syntex"))]
|
||||||
extern crate rustc_plugin;
|
extern crate rustc_plugin;
|
||||||
|
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
use std::io;
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[cfg(not(feature = "with-syntex"))]
|
#[cfg(not(feature = "with-syntex"))]
|
||||||
use syntax::feature_gate::AttributeType;
|
use syntax::feature_gate::AttributeType;
|
||||||
|
|
||||||
@@ -31,6 +36,16 @@ include!(concat!(env!("OUT_DIR"), "/lib.rs"));
|
|||||||
#[cfg(not(feature = "with-syntex"))]
|
#[cfg(not(feature = "with-syntex"))]
|
||||||
include!("lib.rs.in");
|
include!("lib.rs.in");
|
||||||
|
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
|
pub fn expand<S, D>(src: S, dst: D) -> io::Result<()>
|
||||||
|
where S: AsRef<Path>,
|
||||||
|
D: AsRef<Path>,
|
||||||
|
{
|
||||||
|
let mut registry = syntex::Registry::new();
|
||||||
|
register(&mut registry);
|
||||||
|
registry.expand("", src.as_ref(), dst.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "with-syntex")]
|
#[cfg(feature = "with-syntex")]
|
||||||
pub fn register(reg: &mut syntex::Registry) {
|
pub fn register(reg: &mut syntex::Registry) {
|
||||||
use syntax::{ast, fold};
|
use syntax::{ast, fold};
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ fn build_impl_generics(
|
|||||||
// serialized by us so we do not generate a bound. Fields with a `bound`
|
// serialized by us so we do not generate a bound. Fields with a `bound`
|
||||||
// attribute specify their own bound so we do not generate one. All other fields
|
// attribute specify their own bound so we do not generate one. All other fields
|
||||||
// may need a `T: Serialize` bound where T is the type of the field.
|
// may need a `T: Serialize` bound where T is the type of the field.
|
||||||
fn needs_serialize_bound(_: &ast::StructField, attrs: &attr::FieldAttrs) -> bool {
|
fn needs_serialize_bound(attrs: &attr::FieldAttrs) -> bool {
|
||||||
!attrs.skip_serializing_field()
|
!attrs.skip_serializing_field()
|
||||||
&& attrs.serialize_with().is_none()
|
&& attrs.serialize_with().is_none()
|
||||||
&& attrs.ser_bound().is_none()
|
&& attrs.ser_bound().is_none()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_macros"
|
name = "serde_macros"
|
||||||
version = "0.7.8"
|
version = "0.7.10"
|
||||||
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 to auto-generate implementations for the serde framework"
|
description = "Macros to auto-generate implementations for the serde framework"
|
||||||
@@ -18,12 +18,13 @@ nightly-testing = ["clippy", "serde/nightly-testing", "serde_codegen/nightly-tes
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
serde_codegen = { version = "^0.7.8", path = "../serde_codegen", default-features = false, features = ["nightly"] }
|
serde_codegen = { version = "^0.7.10", path = "../serde_codegen", default-features = false, features = ["nightly"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
compiletest_rs = "^0.1.1"
|
compiletest_rs = "^0.1.1"
|
||||||
|
fnv = "1.0"
|
||||||
rustc-serialize = "^0.3.16"
|
rustc-serialize = "^0.3.16"
|
||||||
serde = { version = "^0.7.8", path = "../serde" }
|
serde = { version = "^0.7.10", path = "../serde" }
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "test"
|
name = "test"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_tests"
|
name = "serde_tests"
|
||||||
version = "0.7.8"
|
version = "0.7.10"
|
||||||
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"
|
||||||
@@ -14,14 +14,15 @@ build = "build.rs"
|
|||||||
nightly-testing = ["clippy", "serde/nightly-testing", "serde_codegen/nightly-testing"]
|
nightly-testing = ["clippy", "serde/nightly-testing", "serde_codegen/nightly-testing"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
syntex = { version = "^0.33.0" }
|
syntex = { version = "^0.35.0" }
|
||||||
syntex_syntax = { version = "^0.33.0" }
|
syntex_syntax = { version = "^0.35.0" }
|
||||||
serde_codegen = { version = "*", path = "../serde_codegen", features = ["with-syntex"] }
|
serde_codegen = { version = "*", path = "../serde_codegen", features = ["with-syntex"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
fnv = "1.0"
|
||||||
rustc-serialize = "^0.3.16"
|
rustc-serialize = "^0.3.16"
|
||||||
serde = { version = "*", path = "../serde" }
|
serde = { version = "*", path = "../serde" }
|
||||||
syntex = "^0.33.0"
|
syntex = "^0.35.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ fn main() {
|
|||||||
] {
|
] {
|
||||||
let src = Path::new(src);
|
let src = Path::new(src);
|
||||||
let dst = Path::new(&out_dir).join(dst);
|
let dst = Path::new(&out_dir).join(dst);
|
||||||
|
serde_codegen::expand(&src, &dst).unwrap();
|
||||||
let mut registry = syntex::Registry::new();
|
|
||||||
|
|
||||||
serde_codegen::register(&mut registry);
|
|
||||||
registry.expand("", &src, &dst).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ macro_rules! hashset {
|
|||||||
$(set.insert($value);)+
|
$(set.insert($value);)+
|
||||||
set
|
set
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
($hasher:ident @ $($value:expr),+) => {
|
||||||
|
{
|
||||||
|
use std::hash::BuildHasherDefault;
|
||||||
|
let mut set = HashSet::with_hasher(BuildHasherDefault::<$hasher>::default());
|
||||||
|
$(set.insert($value);)+
|
||||||
|
set
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,5 +83,13 @@ macro_rules! hashmap {
|
|||||||
$(map.insert($key, $value);)+
|
$(map.insert($key, $value);)+
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
($hasher:ident @ $($key:expr => $value:expr),+) => {
|
||||||
|
{
|
||||||
|
use std::hash::BuildHasherDefault;
|
||||||
|
let mut map = HashMap::with_hasher(BuildHasherDefault::<$hasher>::default());
|
||||||
|
$(map.insert($key, $value);)+
|
||||||
|
map
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
|||||||
use std::net;
|
use std::net;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
extern crate fnv;
|
||||||
|
use self::fnv::FnvHasher;
|
||||||
|
|
||||||
use token::{
|
use token::{
|
||||||
Error,
|
Error,
|
||||||
Token,
|
Token,
|
||||||
@@ -284,6 +287,18 @@ declare_tests! {
|
|||||||
Token::TupleStructStart("Anything", Some(0)),
|
Token::TupleStructStart("Anything", Some(0)),
|
||||||
Token::SeqEnd,
|
Token::SeqEnd,
|
||||||
],
|
],
|
||||||
|
hashset![FnvHasher @ 1, 2, 3] => vec![
|
||||||
|
Token::SeqStart(Some(3)),
|
||||||
|
Token::SeqSep,
|
||||||
|
Token::I32(1),
|
||||||
|
|
||||||
|
Token::SeqSep,
|
||||||
|
Token::I32(2),
|
||||||
|
|
||||||
|
Token::SeqSep,
|
||||||
|
Token::I32(3),
|
||||||
|
Token::SeqEnd,
|
||||||
|
],
|
||||||
}
|
}
|
||||||
test_vec {
|
test_vec {
|
||||||
Vec::<isize>::new() => vec![
|
Vec::<isize>::new() => vec![
|
||||||
@@ -532,6 +547,17 @@ declare_tests! {
|
|||||||
Token::StructStart("Anything", Some(0)),
|
Token::StructStart("Anything", Some(0)),
|
||||||
Token::MapEnd,
|
Token::MapEnd,
|
||||||
],
|
],
|
||||||
|
hashmap![FnvHasher @ 1 => 2, 3 => 4] => vec![
|
||||||
|
Token::MapStart(Some(2)),
|
||||||
|
Token::MapSep,
|
||||||
|
Token::I32(1),
|
||||||
|
Token::I32(2),
|
||||||
|
|
||||||
|
Token::MapSep,
|
||||||
|
Token::I32(3),
|
||||||
|
Token::I32(4),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
}
|
}
|
||||||
test_struct {
|
test_struct {
|
||||||
Struct { a: 1, b: 2, c: 0 } => vec![
|
Struct { a: 1, b: 2, c: 0 } => vec![
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||||
use std::net;
|
use std::net;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use token::{self, Token};
|
use token::{self, Token};
|
||||||
|
|
||||||
|
extern crate fnv;
|
||||||
|
use self::fnv::FnvHasher;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@@ -144,6 +147,24 @@ declare_ser_tests! {
|
|||||||
Token::SeqEnd,
|
Token::SeqEnd,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_hashset {
|
||||||
|
HashSet::<isize>::new() => &[
|
||||||
|
Token::SeqStart(Some(0)),
|
||||||
|
Token::SeqEnd,
|
||||||
|
],
|
||||||
|
hashset![1] => &[
|
||||||
|
Token::SeqStart(Some(1)),
|
||||||
|
Token::SeqSep,
|
||||||
|
Token::I32(1),
|
||||||
|
Token::SeqEnd,
|
||||||
|
],
|
||||||
|
hashset![FnvHasher @ 1] => &[
|
||||||
|
Token::SeqStart(Some(1)),
|
||||||
|
Token::SeqSep,
|
||||||
|
Token::I32(1),
|
||||||
|
Token::SeqEnd,
|
||||||
|
],
|
||||||
|
}
|
||||||
test_tuple {
|
test_tuple {
|
||||||
(1,) => &[
|
(1,) => &[
|
||||||
Token::TupleStart(1),
|
Token::TupleStart(1),
|
||||||
@@ -204,6 +225,26 @@ declare_ser_tests! {
|
|||||||
Token::MapEnd,
|
Token::MapEnd,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_hashmap {
|
||||||
|
HashMap::<isize, isize>::new() => &[
|
||||||
|
Token::MapStart(Some(0)),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
hashmap![1 => 2] => &[
|
||||||
|
Token::MapStart(Some(1)),
|
||||||
|
Token::MapSep,
|
||||||
|
Token::I32(1),
|
||||||
|
Token::I32(2),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
hashmap![FnvHasher @ 1 => 2] => &[
|
||||||
|
Token::MapStart(Some(1)),
|
||||||
|
Token::MapSep,
|
||||||
|
Token::I32(1),
|
||||||
|
Token::I32(2),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
}
|
||||||
test_unit_struct {
|
test_unit_struct {
|
||||||
UnitStruct => &[Token::UnitStruct("UnitStruct")],
|
UnitStruct => &[Token::UnitStruct("UnitStruct")],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user