mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 16:17:55 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 78e74886be | |||
| ed603d4580 | |||
| 7220029055 | |||
| 35676305da | |||
| 4ec0a7e672 | |||
| a41dae45a5 | |||
| cb9e1cfb54 | |||
| 54ce7f2e90 | |||
| ddbd139793 | |||
| a070de28e2 | |||
| 57aeb26728 | |||
| a592828808 | |||
| 67d86dcc4f | |||
| 15764cb955 | |||
| 18e077eda9 |
@@ -0,0 +1,7 @@
|
|||||||
|
paths = [
|
||||||
|
"serde",
|
||||||
|
"serde_codegen",
|
||||||
|
"serde_codegen_internals",
|
||||||
|
"serde_macros",
|
||||||
|
"serde_test",
|
||||||
|
]
|
||||||
+2
-2
@@ -2,10 +2,10 @@ sudo: false
|
|||||||
language: rust
|
language: rust
|
||||||
rust:
|
rust:
|
||||||
- stable
|
- stable
|
||||||
- beta
|
|
||||||
- nightly
|
- nightly
|
||||||
- 1.7.0
|
|
||||||
- 1.8.0
|
- 1.8.0
|
||||||
|
- 1.9.0
|
||||||
|
- beta
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# Contributing to Serde
|
||||||
|
|
||||||
|
Serde welcomes contribution from everyone. Here are the guidelines if you are
|
||||||
|
thinking of helping us:
|
||||||
|
|
||||||
|
## Contributions
|
||||||
|
|
||||||
|
Contributions to Serde or its dependencies should be made in the form of GitHub
|
||||||
|
pull requests. Each pull request will be reviewed by a core contributor
|
||||||
|
(someone with permission to land patches) and either landed in the main tree or
|
||||||
|
given feedback for changes that would be required. All contributions should
|
||||||
|
follow this format, even those from core contributors.
|
||||||
|
|
||||||
|
Should you wish to work on an issue, please claim it first by commenting on
|
||||||
|
the GitHub issue that you want to work on it. This is to prevent duplicated
|
||||||
|
efforts from contributors on the same issue.
|
||||||
|
|
||||||
|
## Pull Request Checklist
|
||||||
|
|
||||||
|
- Branch from the master branch and, if needed, rebase to the current master
|
||||||
|
branch before submitting your pull request. If it doesn't merge cleanly with
|
||||||
|
master you may be asked to rebase your changes.
|
||||||
|
|
||||||
|
- Commits should be as small as possible, while ensuring that each commit is
|
||||||
|
correct independently (i.e., each commit should compile and pass tests).
|
||||||
|
|
||||||
|
- If your patch is not getting reviewed or you need a specific person to review
|
||||||
|
it, you can @-reply a reviewer asking for a review in the pull request or a
|
||||||
|
comment, or you can ask for a review in `#serde` on `irc.mozilla.org`.
|
||||||
|
|
||||||
|
- Add tests relevant to the fixed bug or new feature.
|
||||||
|
|
||||||
|
## Conduct
|
||||||
|
|
||||||
|
In all Serde-related forums, we follow the [Rust Code of
|
||||||
|
Conduct](https://www.rust-lang.org/conduct.html). For escalation or moderation
|
||||||
|
issues, please contact Erick (erick.tryzelaar@gmail.com) instead of the Rust
|
||||||
|
moderation team.
|
||||||
|
|
||||||
|
## Communication
|
||||||
|
|
||||||
|
Beyond opening tickets on the
|
||||||
|
[serde-rs/serde](https://github.com/serde-rs/serde) project, Serde contributors
|
||||||
|
frequent the `#serde` channel on
|
||||||
|
[`irc.mozilla.org`](https://wiki.mozilla.org/IRC).
|
||||||
@@ -12,74 +12,100 @@ information. In many situations, the handshake protocol between serializers and
|
|||||||
serializees can be completely optimized away, leaving Serde to perform roughly
|
serializees can be completely optimized away, leaving Serde to perform roughly
|
||||||
the same speed as a hand written serializer for a specific type.
|
the same speed as a hand written serializer for a specific type.
|
||||||
|
|
||||||
Documentation is available at:
|
[Documentation](https://serde-rs.github.io/serde/serde/index.html)
|
||||||
|
|
||||||
* [serde](https://serde-rs.github.io/serde/serde/index.html)
|
Simple Serde Example
|
||||||
|
====================
|
||||||
|
|
||||||
Using Serde with Nightly Rust and serde\_macros
|
Here is a simple example that uses
|
||||||
===============================================
|
[serde_json](https://github.com/serde-rs/json), which uses Serde under the
|
||||||
|
covers, to generate and parse JSON. First, lets start off with the `Cargo.toml`
|
||||||
Here is a simple example that demonstrates how to use Serde by serializing and
|
file:
|
||||||
deserializing to JSON. Serde comes with some powerful code generation libraries
|
|
||||||
that work with Stable and Nightly Rust that eliminate much of the complexity of
|
|
||||||
hand rolling serialization and deserialization for a given type. First lets see
|
|
||||||
how we would use Nightly Rust, which is currently a bit simpler than Stable
|
|
||||||
Rust:
|
|
||||||
|
|
||||||
`Cargo.toml`:
|
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[package]
|
[package]
|
||||||
name = "serde_example_nightly"
|
name = "serde_example"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "*"
|
|
||||||
serde_json = "*"
|
serde_json = "*"
|
||||||
serde_macros = "*"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`src/main.rs`
|
Next, the `src/main.rs` file itself:
|
||||||
|
|
||||||
```rust
|
|
||||||
#![feature(custom_derive, plugin)]
|
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
|
||||||
|
```rust,ignore
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
use std::collections::HashMap;
|
||||||
struct Point {
|
use serde_json::Value;
|
||||||
x: i32,
|
use serde_json::builder::{ArrayBuilder, ObjectBuilder};
|
||||||
y: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let point = Point { x: 1, y: 2 };
|
// Serde has support for many of the builtin Rust types, like arrays..:
|
||||||
let serialized = serde_json::to_string(&point).unwrap();
|
let v = vec![1, 2];
|
||||||
|
let serialized = serde_json::to_string(&v).unwrap();
|
||||||
|
println!("serialized vec: {:?}", serialized);
|
||||||
|
|
||||||
println!("{}", serialized);
|
let deserialized: Vec<u32> = serde_json::from_str(&serialized).unwrap();
|
||||||
|
println!("deserialized vec: {:?}", deserialized);
|
||||||
|
|
||||||
let deserialized: Point = serde_json::from_str(&serialized).unwrap();
|
// ... and maps:
|
||||||
|
let mut map = HashMap::new();
|
||||||
|
map.insert("x".to_string(), 1);
|
||||||
|
map.insert("y".to_string(), 2);
|
||||||
|
|
||||||
println!("{:?}", deserialized);
|
let serialized = serde_json::to_string(&map).unwrap();
|
||||||
|
println!("serialized map: {:?}", serialized);
|
||||||
|
|
||||||
|
let deserialized: HashMap<String, u32> = serde_json::from_str(&serialized).unwrap();
|
||||||
|
println!("deserialized map: {:?}", deserialized);
|
||||||
|
|
||||||
|
// It also can handle complex objects:
|
||||||
|
let value = ObjectBuilder::new()
|
||||||
|
.insert("int", 1)
|
||||||
|
.insert("string", "a string")
|
||||||
|
.insert("array", ArrayBuilder::new()
|
||||||
|
.push(1)
|
||||||
|
.push(2)
|
||||||
|
.unwrap())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let serialized = serde_json::to_string(&value).unwrap();
|
||||||
|
println!("serialized value: {:?}", serialized);
|
||||||
|
|
||||||
|
let deserialized: serde_json::Value = serde_json::from_str(&serialized).unwrap();
|
||||||
|
println!("deserialized value: {:?}", deserialized);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
When run, it produces:
|
This produces the following output when run:
|
||||||
|
|
||||||
```
|
```
|
||||||
% cargo run
|
% cargo run
|
||||||
{"x":1,"y":2}
|
serialized vec: "[1,2]"
|
||||||
Point { x: 1, y: 2 }
|
deserialized vec: [1, 2]
|
||||||
|
serialized map: "{\"y\":2,\"x\":1}"
|
||||||
|
deserialized map: {"y": 2, "x": 1}
|
||||||
|
serialized value: "{\"array\":[1,2],\"int\":1,\"string\":\"a string\"}"
|
||||||
|
deserialized value: {"array":[1,2],"int":1,"string":"a string"}
|
||||||
```
|
```
|
||||||
|
|
||||||
Using Serde with Stable Rust and serde\_codegen
|
Using Serde with Stable Rust and serde\_codegen
|
||||||
===============================================
|
===============================================
|
||||||
|
|
||||||
Stable Rust is a little more complicated because it does not yet support
|
The example before used `serde_json::Value` as the in-memory representation of
|
||||||
compiler plugins. Instead we need to use `serde_codegen` which is based on the
|
the JSON value, but it's also possible for Serde to serialize to and from
|
||||||
code generation library [syntex](https://github.com/serde-rs/syntex):
|
regular Rust types. However, the code to do this can be a bit complicated to
|
||||||
|
write. So instead, Serde also has some powerful code generation libraries that
|
||||||
|
work with Stable and Nightly Rust that eliminate much of the complexity of hand
|
||||||
|
rolling serialization and deserialization for a given type.
|
||||||
|
|
||||||
|
First lets see how we would use Stable Rust, which is currently a tad more
|
||||||
|
complicated than Nightly Rust due to having to work around compiler plugins
|
||||||
|
being unstable. We will use `serde_codegen` which is based on the code
|
||||||
|
generation library [syntex](https://github.com/serde-rs/syntex). First we need
|
||||||
|
to setup the `Cargo.toml` that builds the project:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[package]
|
[package]
|
||||||
@@ -96,16 +122,8 @@ serde = "*"
|
|||||||
serde_json = "*"
|
serde_json = "*"
|
||||||
```
|
```
|
||||||
|
|
||||||
`src/main.rs`:
|
Next, we define our source file, `src/main.rs.in`. Note this is a different
|
||||||
|
extension than usual becaues we need to do code generation:
|
||||||
```rust,ignore
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/main.rs"));
|
|
||||||
```
|
|
||||||
|
|
||||||
`src/main.rs.in`:
|
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@@ -116,17 +134,28 @@ struct Point {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let point = Point { x: 1, y: 2 };
|
let point = Point { x: 1, y: 2 };
|
||||||
let serialized = serde_json::to_string(&point).unwrap();
|
|
||||||
|
|
||||||
|
let serialized = serde_json::to_string(&point).unwrap();
|
||||||
println!("{}", serialized);
|
println!("{}", serialized);
|
||||||
|
|
||||||
let deserialized: Point = serde_json::from_str(&serialized).unwrap();
|
let deserialized: Point = serde_json::from_str(&serialized).unwrap();
|
||||||
|
|
||||||
println!("{:?}", deserialized);
|
println!("{:?}", deserialized);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`build.rs`
|
To finish up the main source code, we define a very simple `src/main.rs` that
|
||||||
|
uses the generated code.
|
||||||
|
|
||||||
|
`src/main.rs`:
|
||||||
|
|
||||||
|
```rust,ignore
|
||||||
|
extern crate serde;
|
||||||
|
extern crate serde_json;
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/main.rs"));
|
||||||
|
```
|
||||||
|
|
||||||
|
The last step is to actually drive the code generation, with the `build.rs` script:
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
extern crate serde_codegen;
|
extern crate serde_codegen;
|
||||||
@@ -144,7 +173,7 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This also produces:
|
All this produces this when run:
|
||||||
|
|
||||||
```
|
```
|
||||||
% cargo run
|
% cargo run
|
||||||
@@ -153,8 +182,63 @@ Point { x: 1, y: 2 }
|
|||||||
```
|
```
|
||||||
|
|
||||||
While this works well with Stable Rust, be aware that the error locations
|
While this works well with Stable Rust, be aware that the error locations
|
||||||
currently are reported in the generated file instead of in the source file. You
|
currently are reported in the generated file instead of in the source file.
|
||||||
may find it easier to develop with Nightly Rust and `serde\_macros`, then
|
|
||||||
|
Using Serde with Nightly Rust and serde\_macros
|
||||||
|
===============================================
|
||||||
|
|
||||||
|
The prior example is a bit more complicated than it needs to be due to compiler
|
||||||
|
plugins being unstable. However, if you are already using Nightly Rust, you can
|
||||||
|
use `serde_macros`, which has a much simpler interface. First, here is the new
|
||||||
|
`Cargo.toml`:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[package]
|
||||||
|
name = "serde_example_nightly"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = "*"
|
||||||
|
serde_json = "*"
|
||||||
|
serde_macros = "*"
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that it doesn't need a build script. Now the `src/main.rs`, which enables
|
||||||
|
the plugin feature, and registers the `serde_macros` plugin:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
#![feature(custom_derive, plugin)]
|
||||||
|
#![plugin(serde_macros)]
|
||||||
|
|
||||||
|
extern crate serde_json;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct Point {
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let point = Point { x: 1, y: 2 };
|
||||||
|
|
||||||
|
let serialized = serde_json::to_string(&point).unwrap();
|
||||||
|
println!("{}", serialized);
|
||||||
|
|
||||||
|
let deserialized: Point = serde_json::from_str(&serialized).unwrap();
|
||||||
|
println!("{:?}", deserialized);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This also produces the same output:
|
||||||
|
|
||||||
|
```
|
||||||
|
% cargo run
|
||||||
|
{"x":1,"y":2}
|
||||||
|
Point { x: 1, y: 2 }
|
||||||
|
```
|
||||||
|
|
||||||
|
You may find it easier to develop with Nightly Rust and `serde\_macros`, then
|
||||||
deploy with Stable Rust and `serde_codegen`. It's possible to combine both
|
deploy with Stable Rust and `serde_codegen`. It's possible to combine both
|
||||||
approaches in one setup:
|
approaches in one setup:
|
||||||
|
|
||||||
@@ -740,6 +824,7 @@ Serialization Formats Using Serde
|
|||||||
| Format | Name |
|
| Format | Name |
|
||||||
| ------ | ---- |
|
| ------ | ---- |
|
||||||
| Bincode | [bincode](https://crates.io/crates/bincode) |
|
| Bincode | [bincode](https://crates.io/crates/bincode) |
|
||||||
|
| env vars | [envy](https://crates.io/crates/envy) |
|
||||||
| JSON | [serde\_json](https://crates.io/crates/serde_json) |
|
| JSON | [serde\_json](https://crates.io/crates/serde_json) |
|
||||||
| MessagePack | [rmp](https://crates.io/crates/rmp) |
|
| MessagePack | [rmp](https://crates.io/crates/rmp) |
|
||||||
| XML | [serde\_xml](https://github.com/serde-rs/xml) |
|
| XML | [serde\_xml](https://github.com/serde-rs/xml) |
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
paths = [
|
|
||||||
"../serde",
|
|
||||||
"../serde_codegen",
|
|
||||||
"../serde_macros",
|
|
||||||
]
|
|
||||||
@@ -9,9 +9,9 @@ default = ["serde_codegen"]
|
|||||||
nightly = ["serde_macros"]
|
nightly = ["serde_macros"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
serde_codegen = { version = "^0.7.13", optional = true }
|
serde_codegen = { version = "^0.7", optional = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "^0.7.13"
|
serde = "^0.7"
|
||||||
serde_json = "^0.7.0"
|
serde_json = "^0.7"
|
||||||
serde_macros = { version = "^0.7.13", optional = true }
|
serde_macros = { version = "^0.7", optional = true }
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "0.7.13"
|
version = "0.7.15"
|
||||||
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,6 +8,8 @@ use error;
|
|||||||
#[cfg(all(not(feature = "std"), feature = "collections"))]
|
#[cfg(all(not(feature = "std"), feature = "collections"))]
|
||||||
use collections::{String, Vec};
|
use collections::{String, Vec};
|
||||||
|
|
||||||
|
use core::fmt;
|
||||||
|
|
||||||
pub mod impls;
|
pub mod impls;
|
||||||
pub mod value;
|
pub mod value;
|
||||||
mod from_primitive;
|
mod from_primitive;
|
||||||
@@ -169,6 +171,46 @@ pub enum Type {
|
|||||||
Bytes,
|
Bytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Type {
|
||||||
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
let display = match *self {
|
||||||
|
Type::Bool => "bool",
|
||||||
|
Type::Usize => "usize",
|
||||||
|
Type::U8 => "u8",
|
||||||
|
Type::U16 => "u16",
|
||||||
|
Type::U32 => "u32",
|
||||||
|
Type::U64 => "u64",
|
||||||
|
Type::Isize => "isize",
|
||||||
|
Type::I8 => "i8",
|
||||||
|
Type::I16 => "i16",
|
||||||
|
Type::I32 => "i32",
|
||||||
|
Type::I64 => "i64",
|
||||||
|
Type::F32 => "f32",
|
||||||
|
Type::F64 => "f64",
|
||||||
|
Type::Char => "char",
|
||||||
|
Type::Str => "str",
|
||||||
|
Type::String => "string",
|
||||||
|
Type::Unit => "unit",
|
||||||
|
Type::Option => "option",
|
||||||
|
Type::Seq => "seq",
|
||||||
|
Type::Map => "map",
|
||||||
|
Type::UnitStruct => "unit struct",
|
||||||
|
Type::NewtypeStruct => "newtype struct",
|
||||||
|
Type::TupleStruct => "tuple struct",
|
||||||
|
Type::Struct => "struct",
|
||||||
|
Type::FieldName => "field name",
|
||||||
|
Type::Tuple => "tuple",
|
||||||
|
Type::Enum => "enum",
|
||||||
|
Type::VariantName => "variant name",
|
||||||
|
Type::StructVariant => "struct variant",
|
||||||
|
Type::TupleVariant => "tuple variant",
|
||||||
|
Type::UnitVariant => "unit variant",
|
||||||
|
Type::Bytes => "bytes",
|
||||||
|
};
|
||||||
|
display.fmt(formatter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// `Deserialize` represents a type that can be deserialized.
|
/// `Deserialize` represents a type that can be deserialized.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen"
|
name = "serde_codegen"
|
||||||
version = "0.7.13"
|
version = "0.7.15"
|
||||||
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"
|
||||||
@@ -24,14 +24,14 @@ with-syntex = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
quasi_codegen = { version = "^0.14.0", optional = true }
|
quasi_codegen = { version = "^0.16.0", optional = true }
|
||||||
syntex = { version = "^0.37.0", optional = true }
|
syntex = { version = "^0.39.0", optional = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
aster = { version = "^0.20.0", default-features = false }
|
aster = { version = "^0.22.0", default-features = false }
|
||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
quasi = { version = "^0.14.0", default-features = false }
|
quasi = { version = "^0.16.0", default-features = false }
|
||||||
quasi_macros = { version = "^0.14.0", optional = true }
|
quasi_macros = { version = "^0.16.0", optional = true }
|
||||||
serde_codegen_internals = { version = "^0.2.0", path = "../serde_codegen_internals", default-features = false }
|
serde_codegen_internals = { version = "^0.4.0", default-features = false }
|
||||||
syntex = { version = "^0.37.0", optional = true }
|
syntex = { version = "^0.39.0", optional = true }
|
||||||
syntex_syntax = { version = "^0.37.0", optional = true }
|
syntex_syntax = { version = "^0.39.0", optional = true }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen_internals"
|
name = "serde_codegen_internals"
|
||||||
version = "0.2.0"
|
version = "0.4.0"
|
||||||
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."
|
||||||
@@ -16,5 +16,5 @@ with-syntex = ["syntex_syntax", "syntex_errors"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
syntex_syntax = { version = "^0.37.0", optional = true }
|
syntex_syntax = { version = "^0.39.0", optional = true }
|
||||||
syntex_errors = { version = "^0.37.0", optional = true }
|
syntex_errors = { version = "^0.39.0", optional = true }
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr::{self, HasAttrs};
|
use syntax::attr::{self, HasAttrs};
|
||||||
use syntax::codemap::{Span, Spanned, respan};
|
use syntax::codemap::{Span, Spanned, respan};
|
||||||
@@ -517,33 +519,33 @@ struct Respanner<'a, 'b: 'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> Folder for Respanner<'a, 'b> {
|
impl<'a, 'b> Folder for Respanner<'a, 'b> {
|
||||||
fn fold_tt(&mut self, tt: TokenTree) -> TokenTree {
|
fn fold_tt(&mut self, tt: &TokenTree) -> TokenTree {
|
||||||
match tt {
|
match *tt {
|
||||||
TokenTree::Token(span, ref tok) => {
|
TokenTree::Token(span, ref tok) => {
|
||||||
TokenTree::Token(
|
TokenTree::Token(
|
||||||
self.new_span(span),
|
self.new_span(span),
|
||||||
self.fold_token(tok.clone())
|
self.fold_token(tok.clone())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TokenTree::Delimited(span, delimed) => {
|
TokenTree::Delimited(span, ref delimed) => {
|
||||||
TokenTree::Delimited(
|
TokenTree::Delimited(
|
||||||
self.new_span(span),
|
self.new_span(span),
|
||||||
tokenstream::Delimited {
|
Rc::new(tokenstream::Delimited {
|
||||||
delim: delimed.delim,
|
delim: delimed.delim,
|
||||||
open_span: delimed.open_span,
|
open_span: delimed.open_span,
|
||||||
tts: self.fold_tts(delimed.tts),
|
tts: self.fold_tts(&delimed.tts),
|
||||||
close_span: delimed.close_span,
|
close_span: delimed.close_span,
|
||||||
}
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TokenTree::Sequence(span, seq) => {
|
TokenTree::Sequence(span, ref seq) => {
|
||||||
TokenTree::Sequence(
|
TokenTree::Sequence(
|
||||||
self.new_span(span),
|
self.new_span(span),
|
||||||
tokenstream::SequenceRepetition {
|
Rc::new(tokenstream::SequenceRepetition {
|
||||||
tts: self.fold_tts(seq.tts),
|
tts: self.fold_tts(&seq.tts),
|
||||||
separator: seq.separator.clone().map(|tok| self.fold_token(tok)),
|
separator: seq.separator.clone().map(|tok| self.fold_token(tok)),
|
||||||
..seq
|
..**seq
|
||||||
}
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -589,7 +591,7 @@ fn parse_string_via_tts<T, F>(cx: &ExtCtxt, name: &str, string: String, action:
|
|||||||
cx.parse_sess()));
|
cx.parse_sess()));
|
||||||
|
|
||||||
// Respan the spans to say they are all coming from this macro.
|
// Respan the spans to say they are all coming from this macro.
|
||||||
let tts = Respanner { cx: cx }.fold_tts(tts);
|
let tts = Respanner { cx: cx }.fold_tts(&tts);
|
||||||
|
|
||||||
let mut parser = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts);
|
let mut parser = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_macros"
|
name = "serde_macros"
|
||||||
version = "0.7.13"
|
version = "0.7.15"
|
||||||
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,15 +18,15 @@ 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.13", path = "../serde_codegen", default-features = false, features = ["nightly"] }
|
serde_codegen = { version = "^0.7.15", default-features = false, features = ["nightly"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
clippy = "^0.0.78"
|
clippy = "^0.0.79"
|
||||||
compiletest_rs = "^0.2.0"
|
compiletest_rs = "^0.2.0"
|
||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
rustc-serialize = "^0.3.16"
|
rustc-serialize = "^0.3.16"
|
||||||
serde = { version = "^0.7.13", path = "../serde" }
|
serde = "0.7.15"
|
||||||
serde_test = { version = "^0.7.13", path = "../serde_test" }
|
serde_test = "0.7.15"
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "test"
|
name = "test"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "0.7.13"
|
version = "0.7.15"
|
||||||
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,4 +11,4 @@ keywords = ["serde", "serialization"]
|
|||||||
include = ["Cargo.toml", "src/**/*.rs"]
|
include = ["Cargo.toml", "src/**/*.rs"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "0.7.13", path = "../serde" }
|
serde = "0.7.15"
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_testing"
|
name = "serde_testing"
|
||||||
version = "0.7.13"
|
version = "0.7.15"
|
||||||
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,13 +14,13 @@ 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]
|
||||||
serde_codegen = { version = "*", path = "../serde_codegen", features = ["with-syntex"] }
|
serde_codegen = { version = "*", features = ["with-syntex"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
rustc-serialize = "^0.3.16"
|
rustc-serialize = "^0.3.16"
|
||||||
serde = { version = "*", path = "../serde" }
|
serde = "*"
|
||||||
serde_test = { version = "*", path = "../serde_test" }
|
serde_test = "*"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
|
|||||||
Reference in New Issue
Block a user