blob: b57bc5fd02d898031f610ade29b352467524b5c6 [file] [log] [blame] [view]
Yi Konge94f3922020-08-31 01:24:17 +08001<!-- Serde readme rendered on crates.io -->
2
3**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
4
5---
6
7You may be looking for:
8
9- [An overview of Serde](https://serde.rs/)
10- [Data formats supported by Serde](https://serde.rs/#data-formats)
11- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/derive.html)
12- [Examples](https://serde.rs/examples.html)
13- [API documentation](https://docs.serde.rs/serde/)
14- [Release notes](https://github.com/serde-rs/serde/releases)
15
16## Serde in action
17
18```rust
19use serde::{Serialize, Deserialize};
20
21#[derive(Serialize, Deserialize, Debug)]
22struct Point {
23 x: i32,
24 y: i32,
25}
26
27fn main() {
28 let point = Point { x: 1, y: 2 };
29
30 // Convert the Point to a JSON string.
31 let serialized = serde_json::to_string(&point).unwrap();
32
33 // Prints serialized = {"x":1,"y":2}
34 println!("serialized = {}", serialized);
35
36 // Convert the JSON string back to a Point.
37 let deserialized: Point = serde_json::from_str(&serialized).unwrap();
38
39 // Prints deserialized = Point { x: 1, y: 2 }
40 println!("deserialized = {:?}", deserialized);
41}
42```
43
44## Getting help
45
46Serde is one of the most widely used Rust libraries so any place that Rustaceans
47congregate will be able to help you out. For chat, consider trying the
David LeGared1bc1012022-03-02 16:21:24 +000048[#rust-questions] or [#rust-beginners] channels of the unofficial community
49Discord (invite: <https://discord.gg/rust-lang-community>, the [#rust-usage] or
50[#beginners] channels of the official Rust Project Discord (invite:
51<https://discord.gg/rust-lang>), or the [#general][zulip] stream in Zulip. For
52asynchronous, consider the [\[rust\] tag on StackOverflow][stackoverflow], the
53[/r/rust] subreddit which has a pinned weekly easy questions post, or the Rust
54[Discourse forum][discourse]. It's acceptable to file a support issue in this
55repo but they tend not to get as many eyes as any of the above and may get
56closed without a response after some time.
Yi Konge94f3922020-08-31 01:24:17 +080057
David LeGared1bc1012022-03-02 16:21:24 +000058[#rust-questions]: https://discord.com/channels/273534239310479360/274215136414400513
59[#rust-beginners]: https://discord.com/channels/273534239310479360/273541522815713281
Yi Konge94f3922020-08-31 01:24:17 +080060[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848
David LeGared1bc1012022-03-02 16:21:24 +000061[#beginners]: https://discord.com/channels/442252698964721669/448238009733742612
Yi Konge94f3922020-08-31 01:24:17 +080062[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general
63[stackoverflow]: https://stackoverflow.com/questions/tagged/rust
64[/r/rust]: https://www.reddit.com/r/rust
65[discourse]: https://users.rust-lang.org