Yi Kong | e94f392 | 2020-08-31 01:24:17 +0800 | [diff] [blame] | 1 | <!-- 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 | |
| 7 | You 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 |
| 19 | use serde::{Serialize, Deserialize}; |
| 20 | |
| 21 | #[derive(Serialize, Deserialize, Debug)] |
| 22 | struct Point { |
| 23 | x: i32, |
| 24 | y: i32, |
| 25 | } |
| 26 | |
| 27 | fn 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 | |
| 46 | Serde is one of the most widely used Rust libraries so any place that Rustaceans |
| 47 | congregate will be able to help you out. For chat, consider trying the |
David LeGare | d1bc101 | 2022-03-02 16:21:24 +0000 | [diff] [blame] | 48 | [#rust-questions] or [#rust-beginners] channels of the unofficial community |
| 49 | Discord (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 |
| 52 | asynchronous, 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 |
| 55 | repo but they tend not to get as many eyes as any of the above and may get |
| 56 | closed without a response after some time. |
Yi Kong | e94f392 | 2020-08-31 01:24:17 +0800 | [diff] [blame] | 57 | |
David LeGare | d1bc101 | 2022-03-02 16:21:24 +0000 | [diff] [blame] | 58 | [#rust-questions]: https://discord.com/channels/273534239310479360/274215136414400513 |
| 59 | [#rust-beginners]: https://discord.com/channels/273534239310479360/273541522815713281 |
Yi Kong | e94f392 | 2020-08-31 01:24:17 +0800 | [diff] [blame] | 60 | [#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848 |
David LeGare | d1bc101 | 2022-03-02 16:21:24 +0000 | [diff] [blame] | 61 | [#beginners]: https://discord.com/channels/442252698964721669/448238009733742612 |
Yi Kong | e94f392 | 2020-08-31 01:24:17 +0800 | [diff] [blame] | 62 | [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 |