17e2e9c0cSopenharmony_ci# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.31] [![serde_derive msrv]][Rust 1.56] 27e2e9c0cSopenharmony_ci 37e2e9c0cSopenharmony_ci[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master 47e2e9c0cSopenharmony_ci[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster 57e2e9c0cSopenharmony_ci[Latest Version]: https://img.shields.io/crates/v/serde.svg 67e2e9c0cSopenharmony_ci[crates.io]: https://crates.io/crates/serde 77e2e9c0cSopenharmony_ci[serde msrv]: https://img.shields.io/crates/msrv/serde.svg?label=serde%20msrv&color=lightgray 87e2e9c0cSopenharmony_ci[serde_derive msrv]: https://img.shields.io/crates/msrv/serde_derive.svg?label=serde_derive%20msrv&color=lightgray 97e2e9c0cSopenharmony_ci[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html 107e2e9c0cSopenharmony_ci[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html 117e2e9c0cSopenharmony_ci 127e2e9c0cSopenharmony_ci**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.** 137e2e9c0cSopenharmony_ci 147e2e9c0cSopenharmony_ci--- 157e2e9c0cSopenharmony_ci 167e2e9c0cSopenharmony_ciYou may be looking for: 177e2e9c0cSopenharmony_ci 187e2e9c0cSopenharmony_ci- [An overview of Serde](https://serde.rs/) 197e2e9c0cSopenharmony_ci- [Data formats supported by Serde](https://serde.rs/#data-formats) 207e2e9c0cSopenharmony_ci- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/derive.html) 217e2e9c0cSopenharmony_ci- [Examples](https://serde.rs/examples.html) 227e2e9c0cSopenharmony_ci- [API documentation](https://docs.rs/serde) 237e2e9c0cSopenharmony_ci- [Release notes](https://github.com/serde-rs/serde/releases) 247e2e9c0cSopenharmony_ci 257e2e9c0cSopenharmony_ci## Serde in action 267e2e9c0cSopenharmony_ci 277e2e9c0cSopenharmony_ci<details> 287e2e9c0cSopenharmony_ci<summary> 297e2e9c0cSopenharmony_ciClick to show Cargo.toml. 307e2e9c0cSopenharmony_ci<a href="https://play.rust-lang.org/?edition=2018&gist=72755f28f99afc95e01d63174b28c1f5" target="_blank">Run this code in the playground.</a> 317e2e9c0cSopenharmony_ci</summary> 327e2e9c0cSopenharmony_ci 337e2e9c0cSopenharmony_ci```toml 347e2e9c0cSopenharmony_ci[dependencies] 357e2e9c0cSopenharmony_ci 367e2e9c0cSopenharmony_ci# The core APIs, including the Serialize and Deserialize traits. Always 377e2e9c0cSopenharmony_ci# required when using Serde. The "derive" feature is only required when 387e2e9c0cSopenharmony_ci# using #[derive(Serialize, Deserialize)] to make Serde work with structs 397e2e9c0cSopenharmony_ci# and enums defined in your crate. 407e2e9c0cSopenharmony_ciserde = { version = "1.0", features = ["derive"] } 417e2e9c0cSopenharmony_ci 427e2e9c0cSopenharmony_ci# Each data format lives in its own crate; the sample code below uses JSON 437e2e9c0cSopenharmony_ci# but you may be using a different one. 447e2e9c0cSopenharmony_ciserde_json = "1.0" 457e2e9c0cSopenharmony_ci``` 467e2e9c0cSopenharmony_ci 477e2e9c0cSopenharmony_ci</details> 487e2e9c0cSopenharmony_ci<p></p> 497e2e9c0cSopenharmony_ci 507e2e9c0cSopenharmony_ci```rust 517e2e9c0cSopenharmony_ciuse serde::{Deserialize, Serialize}; 527e2e9c0cSopenharmony_ci 537e2e9c0cSopenharmony_ci#[derive(Serialize, Deserialize, Debug)] 547e2e9c0cSopenharmony_cistruct Point { 557e2e9c0cSopenharmony_ci x: i32, 567e2e9c0cSopenharmony_ci y: i32, 577e2e9c0cSopenharmony_ci} 587e2e9c0cSopenharmony_ci 597e2e9c0cSopenharmony_cifn main() { 607e2e9c0cSopenharmony_ci let point = Point { x: 1, y: 2 }; 617e2e9c0cSopenharmony_ci 627e2e9c0cSopenharmony_ci // Convert the Point to a JSON string. 637e2e9c0cSopenharmony_ci let serialized = serde_json::to_string(&point).unwrap(); 647e2e9c0cSopenharmony_ci 657e2e9c0cSopenharmony_ci // Prints serialized = {"x":1,"y":2} 667e2e9c0cSopenharmony_ci println!("serialized = {}", serialized); 677e2e9c0cSopenharmony_ci 687e2e9c0cSopenharmony_ci // Convert the JSON string back to a Point. 697e2e9c0cSopenharmony_ci let deserialized: Point = serde_json::from_str(&serialized).unwrap(); 707e2e9c0cSopenharmony_ci 717e2e9c0cSopenharmony_ci // Prints deserialized = Point { x: 1, y: 2 } 727e2e9c0cSopenharmony_ci println!("deserialized = {:?}", deserialized); 737e2e9c0cSopenharmony_ci} 747e2e9c0cSopenharmony_ci``` 757e2e9c0cSopenharmony_ci 767e2e9c0cSopenharmony_ci## Getting help 777e2e9c0cSopenharmony_ci 787e2e9c0cSopenharmony_ciSerde is one of the most widely used Rust libraries so any place that Rustaceans 797e2e9c0cSopenharmony_cicongregate will be able to help you out. For chat, consider trying the 807e2e9c0cSopenharmony_ci[#rust-questions] or [#rust-beginners] channels of the unofficial community 817e2e9c0cSopenharmony_ciDiscord (invite: <https://discord.gg/rust-lang-community>), the [#rust-usage] or 827e2e9c0cSopenharmony_ci[#beginners] channels of the official Rust Project Discord (invite: 837e2e9c0cSopenharmony_ci<https://discord.gg/rust-lang>), or the [#general][zulip] stream in Zulip. For 847e2e9c0cSopenharmony_ciasynchronous, consider the [\[rust\] tag on StackOverflow][stackoverflow], the 857e2e9c0cSopenharmony_ci[/r/rust] subreddit which has a pinned weekly easy questions post, or the Rust 867e2e9c0cSopenharmony_ci[Discourse forum][discourse]. It's acceptable to file a support issue in this 877e2e9c0cSopenharmony_cirepo but they tend not to get as many eyes as any of the above and may get 887e2e9c0cSopenharmony_ciclosed without a response after some time. 897e2e9c0cSopenharmony_ci 907e2e9c0cSopenharmony_ci[#rust-questions]: https://discord.com/channels/273534239310479360/274215136414400513 917e2e9c0cSopenharmony_ci[#rust-beginners]: https://discord.com/channels/273534239310479360/273541522815713281 927e2e9c0cSopenharmony_ci[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848 937e2e9c0cSopenharmony_ci[#beginners]: https://discord.com/channels/442252698964721669/448238009733742612 947e2e9c0cSopenharmony_ci[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general 957e2e9c0cSopenharmony_ci[stackoverflow]: https://stackoverflow.com/questions/tagged/rust 967e2e9c0cSopenharmony_ci[/r/rust]: https://www.reddit.com/r/rust 977e2e9c0cSopenharmony_ci[discourse]: https://users.rust-lang.org 987e2e9c0cSopenharmony_ci 997e2e9c0cSopenharmony_ci<br> 1007e2e9c0cSopenharmony_ci 1017e2e9c0cSopenharmony_ci#### License 1027e2e9c0cSopenharmony_ci 1037e2e9c0cSopenharmony_ci<sup> 1047e2e9c0cSopenharmony_ciLicensed under either of <a href="LICENSE-APACHE">Apache License, Version 1057e2e9c0cSopenharmony_ci2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option. 1067e2e9c0cSopenharmony_ci</sup> 1077e2e9c0cSopenharmony_ci 1087e2e9c0cSopenharmony_ci<br> 1097e2e9c0cSopenharmony_ci 1107e2e9c0cSopenharmony_ci<sub> 1117e2e9c0cSopenharmony_ciUnless you explicitly state otherwise, any contribution intentionally submitted 1127e2e9c0cSopenharmony_cifor inclusion in Serde by you, as defined in the Apache-2.0 license, shall be 1137e2e9c0cSopenharmony_cidual licensed as above, without any additional terms or conditions. 1147e2e9c0cSopenharmony_ci</sub> 115