]> git.proxmox.com Git - rustc.git/blame - src/vendor/serde_derive/README.md
New upstream version 1.23.0+dfsg1
[rustc.git] / src / vendor / serde_derive / README.md
CommitLineData
3b2f2976
XL
1# Serde   [![Build Status]][travis] [![Latest Version]][crates.io]
2
3[Build Status]: https://api.travis-ci.org/serde-rs/serde.svg?branch=master
4[travis]: https://travis-ci.org/serde-rs/serde
5[Latest Version]: https://img.shields.io/crates/v/serde.svg
6[crates.io]: https://crates.io/crates/serde
7
8**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
9
10---
11
12You may be looking for:
13
14- [An overview of Serde](https://serde.rs/)
15- [Data formats supported by Serde](https://serde.rs/#data-formats)
16- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/codegen.html)
17- [Examples](https://serde.rs/examples.html)
18- [API documentation](https://docs.serde.rs/serde/)
19- [Release notes](https://github.com/serde-rs/serde/releases)
20
21## Serde in action
22
abe05a73
XL
23<details>
24<summary>
25Click to show Cargo.toml.
26<a href="http://play.integer32.com/?gist=9003c5b88c1f4989941925d7190c6eec" target="_blank">Run this code in the playground.</a>
27</summary>
28
29```toml
30[dependencies]
31
32# The core APIs, including the Serialize and Deserialize traits. Always
33# required when using Serde.
34serde = "1.0"
35
36# Support for #[derive(Serialize, Deserialize)]. Required if you want Serde
37# to work for structs and enums defined in your crate.
38serde_derive = "1.0"
39
40# Each data format lives in its own crate; the sample code below uses JSON
41# but you may be using a different one.
42serde_json = "1.0"
43```
44
45</details>
46<p></p>
3b2f2976
XL
47
48```rust
49#[macro_use]
50extern crate serde_derive;
51
52extern crate serde;
53extern crate serde_json;
54
55#[derive(Serialize, Deserialize, Debug)]
56struct Point {
57 x: i32,
58 y: i32,
59}
60
61fn main() {
62 let point = Point { x: 1, y: 2 };
63
64 // Convert the Point to a JSON string.
65 let serialized = serde_json::to_string(&point).unwrap();
66
67 // Prints serialized = {"x":1,"y":2}
68 println!("serialized = {}", serialized);
69
70 // Convert the JSON string back to a Point.
71 let deserialized: Point = serde_json::from_str(&serialized).unwrap();
72
73 // Prints deserialized = Point { x: 1, y: 2 }
74 println!("deserialized = {:?}", deserialized);
75}
76```
77
78## Getting help
79
80Serde developers live in the #serde channel on
81[`irc.mozilla.org`](https://wiki.mozilla.org/IRC). The #rust channel is also a
82good resource with generally faster response time but less specific knowledge
83about Serde. If IRC is not your thing or you don't get a good response, we are
84happy to respond to [GitHub issues](https://github.com/serde-rs/serde/issues/new)
85as well.
86
87## License
88
89Serde is licensed under either of
90
91 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
92 http://www.apache.org/licenses/LICENSE-2.0)
93 * MIT license ([LICENSE-MIT](LICENSE-MIT) or
94 http://opensource.org/licenses/MIT)
95
96at your option.
97
98### Contribution
99
100Unless you explicitly state otherwise, any contribution intentionally submitted
101for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be
102dual licensed as above, without any additional terms or conditions.