### Run Serde Documentation Tests Source: https://github.com/serde-rs/serde/blob/master/CONTRIBUTING.md Execute all example code tests within the Serde documentation. This is typically run from the `serde_core` directory. ```sh cargo test ``` -------------------------------- ### Rust Struct with Derive Serialize and Deserialize Source: https://github.com/serde-rs/serde/blob/master/serde_derive/README.md This example demonstrates how to define a Rust struct and derive the Serialize and Deserialize traits from the Serde library, enabling it to be serialized and deserialized. ```rust use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] struct Point { x: i32, y: i32, } fn main() { let point = Point { x: 1, y: 2 }; // Convert the Point to a JSON string. let serialized = serde_json::to_string(&point).unwrap(); // Prints serialized = {"x":1,"y":2} println!("serialized = {}", serialized); // Convert the JSON string back to a Point. let deserialized: Point = serde_json::from_str(&serialized).unwrap(); // Prints deserialized = Point { x: 1, y: 2 } println!("deserialized = {:?}", deserialized); } ``` -------------------------------- ### Basic Serialization and Deserialization with Serde Source: https://github.com/serde-rs/serde/blob/master/serde/crates-io.md Demonstrates how to derive Serialize and Deserialize for a struct and use it to convert between a Rust struct and a JSON string. Ensure the `serde_json` crate is added as a dependency. ```rust use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] struct Point { x: i32, y: i32, } fn main() { let point = Point { x: 1, y: 2 }; // Convert the Point to a JSON string. let serialized = serde_json::to_string(&point).unwrap(); // Prints serialized = {"x":1,"y":2} println!("serialized = {}", serialized); // Convert the JSON string back to a Point. let deserialized: Point = serde_json::from_str(&serialized).unwrap(); // Prints deserialized = Point { x: 1, y: 2 } println!("deserialized = {:?}", deserialized); } ``` -------------------------------- ### Run Full Serde Test Suite Source: https://github.com/serde-rs/serde/blob/master/CONTRIBUTING.md Execute the complete Serde test suite, including tests for unstable features. Requires a nightly Rust compiler and is run from the `test_suite` directory. ```sh cargo +nightly test --features unstable ``` -------------------------------- ### Cargo.toml Dependencies for Serde and JSON Source: https://github.com/serde-rs/serde/blob/master/README.md This snippet shows the necessary dependencies to include in your Cargo.toml file for using Serde with the derive feature and the serde_json crate. ```toml [dependencies] # The core APIs, including the Serialize and Deserialize traits. # Always required when using Serde. The "derive" feature is only required when # using #[derive(Serialize, Deserialize)] to make Serde work with structs # and enums defined in your crate. serde = { version = "1.0", features = ["derive"] } # Each data format lives in its own crate; the sample code below uses JSON # but you may be using a different one. serde_json = "1.0" ``` -------------------------------- ### Cargo.toml Dependencies for Serde Source: https://github.com/serde-rs/serde/blob/master/serde/README.md Include Serde and a data format like serde_json in your Cargo.toml. The 'derive' feature is necessary for using #[derive(Serialize, Deserialize)]. ```toml [dependencies] # The core APIs, including the Serialize and Deserialize traits. serde = { version = "1.0", features = ["derive"] } # Each data format lives in its own crate; the sample code below uses JSON serde_json = "1.0" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.