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