mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-24 20:27:57 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d960571439 | |||
| 1ccc58e2aa | |||
| 34b39083bc | |||
| 48f4deac55 | |||
| 9a0f05d00d | |||
| b47e1a6dc3 | |||
| 39c7797633 | |||
| 368784949e | |||
| 74cf80989d | |||
| f0b4735781 | |||
| 297f373548 | |||
| 81f28da8e1 | |||
| d4bb687032 | |||
| f9bc5037f5 | |||
| 8624ca6f1d | |||
| a9b5cc4830 |
+6
-17
@@ -1,5 +1,6 @@
|
|||||||
sudo: false
|
sudo: false
|
||||||
language: rust
|
language: rust
|
||||||
|
cache: cargo
|
||||||
|
|
||||||
# run builds for all the trains (and more)
|
# run builds for all the trains (and more)
|
||||||
rust:
|
rust:
|
||||||
@@ -8,21 +9,9 @@ rust:
|
|||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
|
|
||||||
before_script:
|
matrix:
|
||||||
- pip install 'travis-cargo<0.2' --user
|
include:
|
||||||
- export PATH=$HOME/.local/bin:$PATH
|
- rust: nightly
|
||||||
|
env: CLIPPY=true
|
||||||
|
|
||||||
script:
|
script: ./travis.sh
|
||||||
- (cd serde && travis-cargo build)
|
|
||||||
- (cd serde && travis-cargo --only beta test)
|
|
||||||
- (cd serde && travis-cargo --only nightly test -- --features unstable-testing)
|
|
||||||
- (cd serde && travis-cargo 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 collections)
|
|
||||||
- (cd test_suite && travis-cargo --only beta test)
|
|
||||||
- (cd test_suite/deps && travis-cargo --only nightly build && cd .. && travis-cargo --only nightly test -- --features unstable-testing)
|
|
||||||
- (cd test_suite/no_std && travis-cargo --only nightly build)
|
|
||||||
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"serde",
|
||||||
|
"serde_codegen_internals",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_test",
|
||||||
|
"test_suite",
|
||||||
|
"test_suite/no_std",
|
||||||
|
]
|
||||||
+2
-5
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "0.9.2"
|
version = "0.9.5"
|
||||||
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"
|
||||||
@@ -22,10 +22,7 @@ std = []
|
|||||||
unstable = []
|
unstable = []
|
||||||
alloc = ["unstable"]
|
alloc = ["unstable"]
|
||||||
collections = ["alloc"]
|
collections = ["alloc"]
|
||||||
unstable-testing = ["clippy", "unstable", "std"]
|
unstable-testing = ["unstable", "std"]
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
clippy = { version = "0.*", optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = "0.9"
|
serde_derive = "0.9"
|
||||||
|
|||||||
+52
-52
@@ -574,7 +574,7 @@ impl<T> Deserialize for [T; 0]
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! array_impls {
|
macro_rules! array_impls {
|
||||||
($($len:expr => ($($name:ident)+))+) => {
|
($($len:expr => ($($n:tt $name:ident)+))+) => {
|
||||||
$(
|
$(
|
||||||
impl<T> Visitor for ArrayVisitor<[T; $len]> where T: Deserialize {
|
impl<T> Visitor for ArrayVisitor<[T; $len]> where T: Deserialize {
|
||||||
type Value = [T; $len];
|
type Value = [T; $len];
|
||||||
@@ -590,7 +590,7 @@ macro_rules! array_impls {
|
|||||||
$(
|
$(
|
||||||
let $name = match try!(visitor.visit()) {
|
let $name = match try!(visitor.visit()) {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => return Err(Error::invalid_length(0, &self)),
|
None => return Err(Error::invalid_length($n, &self)),
|
||||||
};
|
};
|
||||||
)+
|
)+
|
||||||
|
|
||||||
@@ -612,44 +612,44 @@ macro_rules! array_impls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
array_impls! {
|
array_impls! {
|
||||||
1 => (a)
|
1 => (0 a)
|
||||||
2 => (a b)
|
2 => (0 a 1 b)
|
||||||
3 => (a b c)
|
3 => (0 a 1 b 2 c)
|
||||||
4 => (a b c d)
|
4 => (0 a 1 b 2 c 3 d)
|
||||||
5 => (a b c d e)
|
5 => (0 a 1 b 2 c 3 d 4 e)
|
||||||
6 => (a b c d e f)
|
6 => (0 a 1 b 2 c 3 d 4 e 5 f)
|
||||||
7 => (a b c d e f g)
|
7 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g)
|
||||||
8 => (a b c d e f g h)
|
8 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h)
|
||||||
9 => (a b c d e f g h i)
|
9 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i)
|
||||||
10 => (a b c d e f g h i j)
|
10 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j)
|
||||||
11 => (a b c d e f g h i j k)
|
11 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k)
|
||||||
12 => (a b c d e f g h i j k l)
|
12 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l)
|
||||||
13 => (a b c d e f g h i j k l m)
|
13 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m)
|
||||||
14 => (a b c d e f g h i j k l m n)
|
14 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n)
|
||||||
15 => (a b c d e f g h i j k l m n o)
|
15 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o)
|
||||||
16 => (a b c d e f g h i j k l m n o p)
|
16 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p)
|
||||||
17 => (a b c d e f g h i j k l m n o p q)
|
17 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q)
|
||||||
18 => (a b c d e f g h i j k l m n o p q r)
|
18 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r)
|
||||||
19 => (a b c d e f g h i j k l m n o p q r s)
|
19 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s)
|
||||||
20 => (a b c d e f g h i j k l m n o p q r s t)
|
20 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t)
|
||||||
21 => (a b c d e f g h i j k l m n o p q r s t u)
|
21 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u)
|
||||||
22 => (a b c d e f g h i j k l m n o p q r s t u v)
|
22 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v)
|
||||||
23 => (a b c d e f g h i j k l m n o p q r s t u v w)
|
23 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w)
|
||||||
24 => (a b c d e f g h i j k l m n o p q r s t u v w x)
|
24 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x)
|
||||||
25 => (a b c d e f g h i j k l m n o p q r s t u v w x y)
|
25 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x 24 y)
|
||||||
26 => (a b c d e f g h i j k l m n o p q r s t u v w x y z)
|
26 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x 24 y 25 z)
|
||||||
27 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa)
|
27 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x 24 y 25 z 26 aa)
|
||||||
28 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab)
|
28 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x 24 y 25 z 26 aa 27 ab)
|
||||||
29 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac)
|
29 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x 24 y 25 z 26 aa 27 ab 28 ac)
|
||||||
30 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad)
|
30 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x 24 y 25 z 26 aa 27 ab 28 ac 29 ad)
|
||||||
31 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae)
|
31 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x 24 y 25 z 26 aa 27 ab 28 ac 29 ad 30 ae)
|
||||||
32 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af)
|
32 => (0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20 u 21 v 22 w 23 x 24 y 25 z 26 aa 27 ab 28 ac 29 ad 30 ae 31 af)
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! tuple_impls {
|
macro_rules! tuple_impls {
|
||||||
($($len:expr => $visitor:ident => ($($name:ident)+))+) => {
|
($($len:expr => $visitor:ident => ($($n:tt $name:ident)+))+) => {
|
||||||
$(
|
$(
|
||||||
/// Construct a tuple visitor.
|
/// Construct a tuple visitor.
|
||||||
pub struct $visitor<$($name,)+> {
|
pub struct $visitor<$($name,)+> {
|
||||||
@@ -678,7 +678,7 @@ macro_rules! tuple_impls {
|
|||||||
$(
|
$(
|
||||||
let $name = match try!(visitor.visit()) {
|
let $name = match try!(visitor.visit()) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => return Err(Error::invalid_length(0, &self)),
|
None => return Err(Error::invalid_length($n, &self)),
|
||||||
};
|
};
|
||||||
)+
|
)+
|
||||||
|
|
||||||
@@ -699,22 +699,22 @@ macro_rules! tuple_impls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tuple_impls! {
|
tuple_impls! {
|
||||||
1 => TupleVisitor1 => (T0)
|
1 => TupleVisitor1 => (0 T0)
|
||||||
2 => TupleVisitor2 => (T0 T1)
|
2 => TupleVisitor2 => (0 T0 1 T1)
|
||||||
3 => TupleVisitor3 => (T0 T1 T2)
|
3 => TupleVisitor3 => (0 T0 1 T1 2 T2)
|
||||||
4 => TupleVisitor4 => (T0 T1 T2 T3)
|
4 => TupleVisitor4 => (0 T0 1 T1 2 T2 3 T3)
|
||||||
5 => TupleVisitor5 => (T0 T1 T2 T3 T4)
|
5 => TupleVisitor5 => (0 T0 1 T1 2 T2 3 T3 4 T4)
|
||||||
6 => TupleVisitor6 => (T0 T1 T2 T3 T4 T5)
|
6 => TupleVisitor6 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5)
|
||||||
7 => TupleVisitor7 => (T0 T1 T2 T3 T4 T5 T6)
|
7 => TupleVisitor7 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6)
|
||||||
8 => TupleVisitor8 => (T0 T1 T2 T3 T4 T5 T6 T7)
|
8 => TupleVisitor8 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7)
|
||||||
9 => TupleVisitor9 => (T0 T1 T2 T3 T4 T5 T6 T7 T8)
|
9 => TupleVisitor9 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8)
|
||||||
10 => TupleVisitor10 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9)
|
10 => TupleVisitor10 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9)
|
||||||
11 => TupleVisitor11 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10)
|
11 => TupleVisitor11 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10)
|
||||||
12 => TupleVisitor12 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11)
|
12 => TupleVisitor12 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11)
|
||||||
13 => TupleVisitor13 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12)
|
13 => TupleVisitor13 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12)
|
||||||
14 => TupleVisitor14 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13)
|
14 => TupleVisitor14 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12 13 T13)
|
||||||
15 => TupleVisitor15 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14)
|
15 => TupleVisitor15 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12 13 T13 14 T14)
|
||||||
16 => TupleVisitor16 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15)
|
16 => TupleVisitor16 => (0 T0 1 T1 2 T2 3 T3 4 T4 5 T5 6 T6 7 T7 8 T8 9 T9 10 T10 11 T11 12 T12 13 T13 14 T14 15 T15)
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+75
-27
@@ -51,7 +51,9 @@ use bytes;
|
|||||||
|
|
||||||
/// This represents all the possible errors that can occur using the `ValueDeserializer`.
|
/// This represents all the possible errors that can occur using the `ValueDeserializer`.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Error(ErrorImpl);
|
pub struct Error {
|
||||||
|
err: ErrorImpl,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
type ErrorImpl = Box<str>;
|
type ErrorImpl = Box<str>;
|
||||||
@@ -61,19 +63,23 @@ type ErrorImpl = ();
|
|||||||
impl de::Error for Error {
|
impl de::Error for Error {
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
fn custom<T: Display>(msg: T) -> Self {
|
fn custom<T: Display>(msg: T) -> Self {
|
||||||
Error(msg.to_string().into_boxed_str())
|
Error {
|
||||||
|
err: msg.to_string().into_boxed_str(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
#[cfg(not(any(feature = "std", feature = "collections")))]
|
||||||
fn custom<T: Display>(_msg: T) -> Self {
|
fn custom<T: Display>(_msg: T) -> Self {
|
||||||
Error(())
|
Error {
|
||||||
|
err: (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
formatter.write_str(&self.0)
|
formatter.write_str(&self.err)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
#[cfg(not(any(feature = "std", feature = "collections")))]
|
||||||
@@ -85,7 +91,7 @@ impl Display for Error {
|
|||||||
impl error::Error for Error {
|
impl error::Error for Error {
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
&self.0
|
&self.err
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
#[cfg(not(any(feature = "std", feature = "collections")))]
|
||||||
@@ -113,12 +119,16 @@ impl<E> ValueDeserializer<E> for ()
|
|||||||
type Deserializer = UnitDeserializer<E>;
|
type Deserializer = UnitDeserializer<E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> UnitDeserializer<E> {
|
fn into_deserializer(self) -> UnitDeserializer<E> {
|
||||||
UnitDeserializer(PhantomData)
|
UnitDeserializer {
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper deserializer that deserializes a `()`.
|
/// A helper deserializer that deserializes a `()`.
|
||||||
pub struct UnitDeserializer<E>(PhantomData<E>);
|
pub struct UnitDeserializer<E> {
|
||||||
|
marker: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
impl<E> de::Deserializer for UnitDeserializer<E>
|
impl<E> de::Deserializer for UnitDeserializer<E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
@@ -149,7 +159,10 @@ impl<E> de::Deserializer for UnitDeserializer<E>
|
|||||||
macro_rules! primitive_deserializer {
|
macro_rules! primitive_deserializer {
|
||||||
($ty:ty, $name:ident, $method:ident $($cast:tt)*) => {
|
($ty:ty, $name:ident, $method:ident $($cast:tt)*) => {
|
||||||
/// A helper deserializer that deserializes a number.
|
/// A helper deserializer that deserializes a number.
|
||||||
pub struct $name<E>($ty, PhantomData<E>);
|
pub struct $name<E> {
|
||||||
|
value: $ty,
|
||||||
|
marker: PhantomData<E>
|
||||||
|
}
|
||||||
|
|
||||||
impl<E> ValueDeserializer<E> for $ty
|
impl<E> ValueDeserializer<E> for $ty
|
||||||
where E: de::Error,
|
where E: de::Error,
|
||||||
@@ -157,7 +170,10 @@ macro_rules! primitive_deserializer {
|
|||||||
type Deserializer = $name<E>;
|
type Deserializer = $name<E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> $name<E> {
|
fn into_deserializer(self) -> $name<E> {
|
||||||
$name(self, PhantomData)
|
$name {
|
||||||
|
value: self,
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +191,7 @@ macro_rules! primitive_deserializer {
|
|||||||
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where V: de::Visitor,
|
where V: de::Visitor,
|
||||||
{
|
{
|
||||||
visitor.$method(self.0 $($cast)*)
|
visitor.$method(self.value $($cast)*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,7 +215,10 @@ primitive_deserializer!(char, CharDeserializer, visit_char);
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// A helper deserializer that deserializes a `&str`.
|
/// A helper deserializer that deserializes a `&str`.
|
||||||
pub struct StrDeserializer<'a, E>(&'a str, PhantomData<E>);
|
pub struct StrDeserializer<'a, E> {
|
||||||
|
value: &'a str,
|
||||||
|
marker: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, E> ValueDeserializer<E> for &'a str
|
impl<'a, E> ValueDeserializer<E> for &'a str
|
||||||
where E: de::Error,
|
where E: de::Error,
|
||||||
@@ -207,7 +226,10 @@ impl<'a, E> ValueDeserializer<E> for &'a str
|
|||||||
type Deserializer = StrDeserializer<'a, E>;
|
type Deserializer = StrDeserializer<'a, E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> StrDeserializer<'a, E> {
|
fn into_deserializer(self) -> StrDeserializer<'a, E> {
|
||||||
StrDeserializer(self, PhantomData)
|
StrDeserializer {
|
||||||
|
value: self,
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +241,7 @@ impl<'a, E> de::Deserializer for StrDeserializer<'a, 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: de::Visitor,
|
where V: de::Visitor,
|
||||||
{
|
{
|
||||||
visitor.visit_str(self.0)
|
visitor.visit_str(self.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_enum<V>(self,
|
fn deserialize_enum<V>(self,
|
||||||
@@ -255,7 +277,10 @@ impl<'a, E> de::EnumVisitor for StrDeserializer<'a, E>
|
|||||||
|
|
||||||
/// A helper deserializer that deserializes a `String`.
|
/// A helper deserializer that deserializes a `String`.
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
pub struct StringDeserializer<E>(String, PhantomData<E>);
|
pub struct StringDeserializer<E> {
|
||||||
|
value: String,
|
||||||
|
marker: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<E> ValueDeserializer<E> for String
|
impl<E> ValueDeserializer<E> for String
|
||||||
@@ -264,7 +289,10 @@ impl<E> ValueDeserializer<E> for String
|
|||||||
type Deserializer = StringDeserializer<E>;
|
type Deserializer = StringDeserializer<E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> StringDeserializer<E> {
|
fn into_deserializer(self) -> StringDeserializer<E> {
|
||||||
StringDeserializer(self, PhantomData)
|
StringDeserializer {
|
||||||
|
value: self,
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +305,7 @@ impl<E> de::Deserializer for StringDeserializer<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: de::Visitor,
|
where V: de::Visitor,
|
||||||
{
|
{
|
||||||
visitor.visit_string(self.0)
|
visitor.visit_string(self.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_enum<V>(self,
|
fn deserialize_enum<V>(self,
|
||||||
@@ -314,7 +342,10 @@ impl<'a, E> de::EnumVisitor for StringDeserializer<E>
|
|||||||
|
|
||||||
/// A helper deserializer that deserializes a `String`.
|
/// A helper deserializer that deserializes a `String`.
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
pub struct CowStrDeserializer<'a, E>(Cow<'a, str>, PhantomData<E>);
|
pub struct CowStrDeserializer<'a, E> {
|
||||||
|
value: Cow<'a, str>,
|
||||||
|
marker: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<'a, E> ValueDeserializer<E> for Cow<'a, str>
|
impl<'a, E> ValueDeserializer<E> for Cow<'a, str>
|
||||||
@@ -323,7 +354,10 @@ impl<'a, E> ValueDeserializer<E> for Cow<'a, str>
|
|||||||
type Deserializer = CowStrDeserializer<'a, E>;
|
type Deserializer = CowStrDeserializer<'a, E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> CowStrDeserializer<'a, E> {
|
fn into_deserializer(self) -> CowStrDeserializer<'a, E> {
|
||||||
CowStrDeserializer(self, PhantomData)
|
CowStrDeserializer {
|
||||||
|
value: self,
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +370,7 @@ impl<'a, E> de::Deserializer for CowStrDeserializer<'a, 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: de::Visitor,
|
where V: de::Visitor,
|
||||||
{
|
{
|
||||||
match self.0 {
|
match self.value {
|
||||||
Cow::Borrowed(string) => visitor.visit_str(string),
|
Cow::Borrowed(string) => visitor.visit_str(string),
|
||||||
Cow::Owned(string) => visitor.visit_string(string),
|
Cow::Owned(string) => visitor.visit_string(string),
|
||||||
}
|
}
|
||||||
@@ -885,12 +919,18 @@ impl<'a, E> ValueDeserializer<E> for bytes::Bytes<'a>
|
|||||||
type Deserializer = BytesDeserializer<'a, E>;
|
type Deserializer = BytesDeserializer<'a, E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> BytesDeserializer<'a, E> {
|
fn into_deserializer(self) -> BytesDeserializer<'a, E> {
|
||||||
BytesDeserializer(self.into(), PhantomData)
|
BytesDeserializer {
|
||||||
|
value: self.into(),
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper deserializer that deserializes a `&[u8]`.
|
/// A helper deserializer that deserializes a `&[u8]`.
|
||||||
pub struct BytesDeserializer<'a, E>(&'a [u8], PhantomData<E>);
|
pub struct BytesDeserializer<'a, E> {
|
||||||
|
value: &'a [u8],
|
||||||
|
marker: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, E> de::Deserializer for BytesDeserializer<'a, E>
|
impl<'a, E> de::Deserializer for BytesDeserializer<'a, E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
@@ -900,7 +940,7 @@ impl<'a, E> de::Deserializer for BytesDeserializer<'a, 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: de::Visitor,
|
where V: de::Visitor,
|
||||||
{
|
{
|
||||||
visitor.visit_bytes(self.0)
|
visitor.visit_bytes(self.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
@@ -919,13 +959,19 @@ impl<E> ValueDeserializer<E> for bytes::ByteBuf
|
|||||||
type Deserializer = ByteBufDeserializer<E>;
|
type Deserializer = ByteBufDeserializer<E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> Self::Deserializer {
|
fn into_deserializer(self) -> Self::Deserializer {
|
||||||
ByteBufDeserializer(self.into(), PhantomData)
|
ByteBufDeserializer {
|
||||||
|
value: self.into(),
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper deserializer that deserializes a `Vec<u8>`.
|
/// A helper deserializer that deserializes a `Vec<u8>`.
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
pub struct ByteBufDeserializer<E>(Vec<u8>, PhantomData<E>);
|
pub struct ByteBufDeserializer<E> {
|
||||||
|
value: Vec<u8>,
|
||||||
|
marker: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
impl<E> de::Deserializer for ByteBufDeserializer<E>
|
impl<E> de::Deserializer for ByteBufDeserializer<E>
|
||||||
@@ -936,7 +982,7 @@ impl<E> de::Deserializer for ByteBufDeserializer<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: de::Visitor,
|
where V: de::Visitor,
|
||||||
{
|
{
|
||||||
visitor.visit_byte_buf(self.0)
|
visitor.visit_byte_buf(self.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
forward_to_deserialize! {
|
forward_to_deserialize! {
|
||||||
@@ -952,10 +998,12 @@ mod private {
|
|||||||
use de::{self, Unexpected};
|
use de::{self, Unexpected};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
pub struct UnitOnly<E>(PhantomData<E>);
|
pub struct UnitOnly<E> {
|
||||||
|
marker: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn unit_only<T, E>(t: T) -> (T, UnitOnly<E>) {
|
pub fn unit_only<T, E>(t: T) -> (T, UnitOnly<E>) {
|
||||||
(t, UnitOnly(PhantomData))
|
(t, UnitOnly { marker: PhantomData })
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> de::VariantVisitor for UnitOnly<E>
|
impl<E> de::VariantVisitor for UnitOnly<E>
|
||||||
|
|||||||
+1
-3
@@ -64,9 +64,7 @@
|
|||||||
#![cfg_attr(feature = "unstable", feature(nonzero, inclusive_range, zero_one))]
|
#![cfg_attr(feature = "unstable", feature(nonzero, inclusive_range, zero_one))]
|
||||||
#![cfg_attr(feature = "alloc", feature(alloc))]
|
#![cfg_attr(feature = "alloc", feature(alloc))]
|
||||||
#![cfg_attr(feature = "collections", feature(collections, enumset))]
|
#![cfg_attr(feature = "collections", feature(collections, enumset))]
|
||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
#![cfg_attr(feature = "cargo-clippy", allow(linkedlist, type_complexity, doc_markdown))]
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
|
||||||
#![cfg_attr(feature = "clippy", allow(linkedlist, type_complexity, doc_markdown))]
|
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
#[cfg(feature = "collections")]
|
#[cfg(feature = "collections")]
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ impl<'a, I> Serialize for Iterator<I>
|
|||||||
where S: Serializer,
|
where S: Serializer,
|
||||||
{
|
{
|
||||||
// FIXME: use specialization to prevent invalidating the object in case of clonable iterators?
|
// FIXME: use specialization to prevent invalidating the object in case of clonable iterators?
|
||||||
let iter = match self.0.borrow_mut().take() {
|
let iter = match self.data.borrow_mut().take() {
|
||||||
Some(iter) => iter.into_iter(),
|
Some(iter) => iter.into_iter(),
|
||||||
None => return Err(Error::custom("Iterator used twice")),
|
None => return Err(Error::custom("Iterator used twice")),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,177 @@
|
|||||||
|
//! This module contains `Impossible` serializer and its implementations.
|
||||||
|
|
||||||
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
|
use ser::{
|
||||||
|
self,
|
||||||
|
Serialize,
|
||||||
|
SerializeSeq,
|
||||||
|
SerializeTuple,
|
||||||
|
SerializeTupleStruct,
|
||||||
|
SerializeTupleVariant,
|
||||||
|
SerializeMap,
|
||||||
|
SerializeStruct,
|
||||||
|
SerializeStructVariant,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Helper type for implementing a `Serializer` that does not support
|
||||||
|
/// serializing one of the compound types.
|
||||||
|
///
|
||||||
|
/// This type cannot be instantiated, but implements every one of the traits
|
||||||
|
/// corresponding to the `Serializer` compound types: `SerializeSeq`,
|
||||||
|
/// `SerializeTuple`, `SerializeTupleStruct`, `SerializeTupleVariant`,
|
||||||
|
/// `SerializeMap`, `SerializeStruct`, and `SerializeStructVariant`.
|
||||||
|
///
|
||||||
|
/// ```rust,ignore
|
||||||
|
/// impl Serializer for MySerializer {
|
||||||
|
/// type Ok = ();
|
||||||
|
/// type Error = Error;
|
||||||
|
///
|
||||||
|
/// type SerializeSeq = Impossible<(), Error>;
|
||||||
|
/// /* other associated types */
|
||||||
|
///
|
||||||
|
/// /// This data format does not support serializing sequences.
|
||||||
|
/// fn serialize_seq(self,
|
||||||
|
/// len: Option<usize>)
|
||||||
|
/// -> Result<Self::SerializeSeq, Error> {
|
||||||
|
/// // Given Impossible cannot be instantiated, the only
|
||||||
|
/// // thing we can do here is to return an error.
|
||||||
|
/// Err(...)
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// /* other Serializer methods */
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub struct Impossible<Ok, E> {
|
||||||
|
void: Void,
|
||||||
|
_marker: PhantomData<(Ok, E)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Void {}
|
||||||
|
|
||||||
|
impl<Ok, E> SerializeSeq for Impossible<Ok, E>
|
||||||
|
where E: ser::Error,
|
||||||
|
{
|
||||||
|
type Ok = Ok;
|
||||||
|
type Error = E;
|
||||||
|
|
||||||
|
fn serialize_element<T: ?Sized + Serialize>(&mut self,
|
||||||
|
_value: &T)
|
||||||
|
-> Result<(), E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(self) -> Result<Ok, E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Ok, E> SerializeTuple for Impossible<Ok, E>
|
||||||
|
where E: ser::Error,
|
||||||
|
{
|
||||||
|
type Ok = Ok;
|
||||||
|
type Error = E;
|
||||||
|
|
||||||
|
fn serialize_element<T: ?Sized + Serialize>(&mut self,
|
||||||
|
_value: &T)
|
||||||
|
-> Result<(), E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(self) -> Result<Ok, E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Ok, E> SerializeTupleStruct for Impossible<Ok, E>
|
||||||
|
where E: ser::Error,
|
||||||
|
{
|
||||||
|
type Ok = Ok;
|
||||||
|
type Error = E;
|
||||||
|
|
||||||
|
fn serialize_field<T: ?Sized + Serialize>(&mut self,
|
||||||
|
_value: &T)
|
||||||
|
-> Result<(), E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(self) -> Result<Ok, E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Ok, E> SerializeTupleVariant for Impossible<Ok, E>
|
||||||
|
where E: ser::Error,
|
||||||
|
{
|
||||||
|
type Ok = Ok;
|
||||||
|
type Error = E;
|
||||||
|
|
||||||
|
fn serialize_field<T: ?Sized + Serialize>(&mut self,
|
||||||
|
_value: &T)
|
||||||
|
-> Result<(), E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(self) -> Result<Ok, E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Ok, E> SerializeMap for Impossible<Ok, E>
|
||||||
|
where E: ser::Error,
|
||||||
|
{
|
||||||
|
type Ok = Ok;
|
||||||
|
type Error = E;
|
||||||
|
|
||||||
|
fn serialize_key<T: ?Sized + Serialize>(&mut self,
|
||||||
|
_key: &T)
|
||||||
|
-> Result<(), E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn serialize_value<T: ?Sized + Serialize>(&mut self,
|
||||||
|
_value: &T)
|
||||||
|
-> Result<(), E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(self) -> Result<Ok, E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Ok, E> SerializeStruct for Impossible<Ok, E>
|
||||||
|
where E: ser::Error,
|
||||||
|
{
|
||||||
|
type Ok = Ok;
|
||||||
|
type Error = E;
|
||||||
|
|
||||||
|
fn serialize_field<T: ?Sized + Serialize>(&mut self,
|
||||||
|
_key: &'static str,
|
||||||
|
_value: &T)
|
||||||
|
-> Result<(), E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(self) -> Result<Ok, E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Ok, E> SerializeStructVariant for Impossible<Ok, E>
|
||||||
|
where E: ser::Error,
|
||||||
|
{
|
||||||
|
type Ok = Ok;
|
||||||
|
type Error = E;
|
||||||
|
|
||||||
|
fn serialize_field<T: ?Sized + Serialize>(&mut self,
|
||||||
|
_key: &'static str,
|
||||||
|
_value: &T)
|
||||||
|
-> Result<(), E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end(self) -> Result<Ok, E> {
|
||||||
|
match self.void {}
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-3
@@ -104,6 +104,9 @@ use core::cell::RefCell;
|
|||||||
use core::fmt::Display;
|
use core::fmt::Display;
|
||||||
|
|
||||||
mod impls;
|
mod impls;
|
||||||
|
mod impossible;
|
||||||
|
|
||||||
|
pub use self::impossible::Impossible;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -802,9 +805,12 @@ pub trait SerializeStructVariant {
|
|||||||
/// of this with the `serde::ser::iterator` function every time you want to
|
/// of this with the `serde::ser::iterator` function every time you want to
|
||||||
/// serialize an iterator.
|
/// serialize an iterator.
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
pub struct Iterator<I>(RefCell<Option<I>>)
|
pub struct Iterator<I>
|
||||||
where <I as IntoIterator>::Item: Serialize,
|
where <I as IntoIterator>::Item: Serialize,
|
||||||
I: IntoIterator;
|
I: IntoIterator
|
||||||
|
{
|
||||||
|
data: RefCell<Option<I>>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a wrapper type that can be passed to any function expecting a
|
/// Create a wrapper type that can be passed to any function expecting a
|
||||||
/// `Serialize` and will serialize the given iterator as a sequence.
|
/// `Serialize` and will serialize the given iterator as a sequence.
|
||||||
@@ -813,5 +819,7 @@ pub fn iterator<I>(iter: I) -> Iterator<I>
|
|||||||
where <I as IntoIterator>::Item: Serialize,
|
where <I as IntoIterator>::Item: Serialize,
|
||||||
I: IntoIterator
|
I: IntoIterator
|
||||||
{
|
{
|
||||||
Iterator(RefCell::new(Some(iter)))
|
Iterator {
|
||||||
|
data: RefCell::new(Some(iter)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen_internals"
|
name = "serde_codegen_internals"
|
||||||
version = "0.12.0"
|
version = "0.12.1"
|
||||||
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 = "AST representation used by Serde codegen. Unstable."
|
description = "AST representation used by Serde codegen. Unstable."
|
||||||
@@ -10,11 +10,7 @@ documentation = "https://docs.serde.rs/serde_codegen_internals/"
|
|||||||
keywords = ["serde", "serialization"]
|
keywords = ["serde", "serialization"]
|
||||||
include = ["Cargo.toml", "src/**/*.rs"]
|
include = ["Cargo.toml", "src/**/*.rs"]
|
||||||
|
|
||||||
[features]
|
|
||||||
unstable-testing = ["clippy"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "0.*", optional = true }
|
|
||||||
syn = "0.11"
|
syn = "0.11"
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
|
||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
|
||||||
|
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
|
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "0.9.2"
|
version = "0.9.5"
|
||||||
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)]"
|
||||||
@@ -12,7 +12,6 @@ include = ["Cargo.toml", "src/**/*.rs"]
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
unstable = []
|
unstable = []
|
||||||
unstable-testing = ["clippy", "serde_codegen_internals/unstable-testing"]
|
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "serde-rs/serde" }
|
travis-ci = { repository = "serde-rs/serde" }
|
||||||
@@ -22,7 +21,6 @@ name = "serde_derive"
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "0.*", optional = true }
|
|
||||||
quote = "0.3.8"
|
quote = "0.3.8"
|
||||||
serde_codegen_internals = { version = "=0.12.0", default-features = false, path = "../serde_codegen_internals" }
|
serde_codegen_internals = { version = "=0.12.1", default-features = false, path = "../serde_codegen_internals" }
|
||||||
syn = { version = "0.11", features = ["aster", "visit"] }
|
syn = { version = "0.11", features = ["aster", "visit"] }
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
|
||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
#![cfg_attr(feature = "cargo-clippy", allow(used_underscore_binding))]
|
||||||
#![cfg_attr(feature = "clippy", allow(too_many_arguments))]
|
|
||||||
#![cfg_attr(feature = "clippy", allow(used_underscore_binding))]
|
|
||||||
|
|
||||||
// The `quote!` macro requires deep recursion.
|
// The `quote!` macro requires deep recursion.
|
||||||
#![recursion_limit = "192"]
|
#![recursion_limit = "192"]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "0.9.2"
|
version = "0.9.5"
|
||||||
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"
|
||||||
@@ -11,11 +11,7 @@ readme = "../README.md"
|
|||||||
keywords = ["serde", "serialization"]
|
keywords = ["serde", "serialization"]
|
||||||
include = ["Cargo.toml", "src/**/*.rs"]
|
include = ["Cargo.toml", "src/**/*.rs"]
|
||||||
|
|
||||||
[features]
|
|
||||||
unstable-testing = ["clippy"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "0.*", optional = true }
|
|
||||||
serde = { version = "0.9", path = "../serde" }
|
serde = { version = "0.9", path = "../serde" }
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
|
||||||
|
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
mod assert;
|
mod assert;
|
||||||
|
|||||||
@@ -13,11 +13,8 @@ publish = false
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
unstable-testing = [
|
unstable-testing = [
|
||||||
"clippy",
|
|
||||||
"compiletest_rs",
|
"compiletest_rs",
|
||||||
"serde/unstable-testing",
|
"serde/unstable-testing",
|
||||||
"serde_derive/unstable-testing",
|
|
||||||
"serde_test/unstable-testing",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
@@ -28,7 +25,6 @@ serde_derive = { path = "../serde_derive" }
|
|||||||
serde_test = { path = "../serde_test" }
|
serde_test = { path = "../serde_test" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "0.*", optional = true }
|
|
||||||
compiletest_rs = { version = "0.2", optional = true }
|
compiletest_rs = { version = "0.2", optional = true }
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ version = "0.0.0"
|
|||||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { path = "../../serde" }
|
serde = { path = "../../serde" }
|
||||||
serde_derive = { path = "../../serde_derive" }
|
serde_derive = { path = "../../serde_derive" }
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ pub extern fn rust_eh_unwind_resume() {}
|
|||||||
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
|
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
|
||||||
_file: &'static str,
|
_file: &'static str,
|
||||||
_line: u32) -> ! {
|
_line: u32) -> ! {
|
||||||
loop {}
|
unsafe {
|
||||||
|
libc::abort()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
|
||||||
|
|
||||||
#![cfg_attr(feature = "unstable-testing", feature(test, non_ascii_idents))]
|
#![cfg_attr(feature = "unstable-testing", feature(test, non_ascii_idents))]
|
||||||
|
|
||||||
#[cfg(feature = "unstable-testing")]
|
#[cfg(feature = "unstable-testing")]
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ macro_rules! declare_tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! declare_error_tests {
|
macro_rules! declare_error_tests {
|
||||||
($($name:ident<$target:ident> { $tokens:expr, $expected:expr, })+) => {
|
($($name:ident<$target:ty> { $tokens:expr, $expected:expr, })+) => {
|
||||||
$(
|
$(
|
||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
fn $name() {
|
||||||
@@ -936,4 +936,22 @@ declare_error_tests! {
|
|||||||
],
|
],
|
||||||
Error::Message("invalid value: integer `4`, expected variant index 0 <= i < 4".into()),
|
Error::Message("invalid value: integer `4`, expected variant index 0 <= i < 4".into()),
|
||||||
}
|
}
|
||||||
|
test_short_tuple<(u8, u8, u8)> {
|
||||||
|
&[
|
||||||
|
Token::TupleStart(1),
|
||||||
|
Token::TupleSep,
|
||||||
|
Token::U8(1),
|
||||||
|
Token::TupleEnd,
|
||||||
|
],
|
||||||
|
Error::Message("invalid length 1, expected a tuple of size 3".into()),
|
||||||
|
}
|
||||||
|
test_short_array<[u8; 3]> {
|
||||||
|
&[
|
||||||
|
Token::SeqStart(Some(1)),
|
||||||
|
Token::SeqSep,
|
||||||
|
Token::U8(1),
|
||||||
|
Token::SeqEnd,
|
||||||
|
],
|
||||||
|
Error::Message("invalid length 1, expected an array of length 3".into()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
channel() {
|
||||||
|
if [ -n "${TRAVIS}" ]; then
|
||||||
|
if [ "${TRAVIS_RUST_VERSION}" = "${CHANNEL}" ]; then
|
||||||
|
pwd
|
||||||
|
(set -x; cargo "$@")
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
pwd
|
||||||
|
(set -x; cargo "+${CHANNEL}" "$@")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n "${CLIPPY}" ]; then
|
||||||
|
# cached installation will not work on a later nightly
|
||||||
|
if [ -n "${TRAVIS}" ] && ! cargo install clippy --debug --force; then
|
||||||
|
echo "COULD NOT COMPILE CLIPPY, IGNORING CLIPPY TESTS"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$DIR/serde"
|
||||||
|
cargo clippy --features unstable-testing -- -Dclippy
|
||||||
|
|
||||||
|
cd "$DIR/serde_derive"
|
||||||
|
cargo clippy --features unstable-testing -- -Dclippy
|
||||||
|
|
||||||
|
cd "$DIR/test_suite"
|
||||||
|
cargo clippy --features unstable-testing -- -Dclippy
|
||||||
|
|
||||||
|
cd "$DIR/test_suite/no_std"
|
||||||
|
cargo clippy -- -Dclippy
|
||||||
|
else
|
||||||
|
CHANNEL=nightly
|
||||||
|
cargo clean
|
||||||
|
cd "$DIR/serde"
|
||||||
|
channel build
|
||||||
|
channel build --no-default-features
|
||||||
|
channel build --no-default-features --features alloc
|
||||||
|
channel build --no-default-features --features collections
|
||||||
|
channel test --features unstable-testing
|
||||||
|
cd "$DIR/test_suite/deps"
|
||||||
|
channel build
|
||||||
|
cd "$DIR/test_suite"
|
||||||
|
channel test --features unstable-testing
|
||||||
|
cd "$DIR/test_suite/no_std"
|
||||||
|
channel build
|
||||||
|
|
||||||
|
CHANNEL=beta
|
||||||
|
cargo clean
|
||||||
|
cd "$DIR/serde"
|
||||||
|
channel build
|
||||||
|
cd "$DIR/test_suite"
|
||||||
|
channel test
|
||||||
|
|
||||||
|
CHANNEL=stable
|
||||||
|
cargo clean
|
||||||
|
cd "$DIR/serde"
|
||||||
|
channel build
|
||||||
|
channel build --no-default-features
|
||||||
|
|
||||||
|
CHANNEL=1.13.0
|
||||||
|
cargo clean
|
||||||
|
cd "$DIR/serde"
|
||||||
|
channel build
|
||||||
|
channel build --no-default-features
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user