Crate serde_with [−] [src]
This crate provides custom de/serialization helpers to use in combination with serde's with-annotation.
Serde tracks a wishlist of similar helpers at serde#553.
Usage
[dependencies.serde_with]
version = "..."
features = [ ... ]
The crate is divided into different modules. They contain helpers for external crates and must be enabled with the correspondig feature.
Annotate your struct or enum to enable the custom de/serializer.
#[derive(Deserialize, Serialize)] struct Foo { #[serde(with = "serde_with::rust::display_fromstr")] bar: u8, }
Most helpers implement both deserialize and serialize. If you do not want to derive both, you can simply derive only the necessary parts. If you want to mix different helpers, you can write your annotations like
#[cfg(feature = "json")] #[derive(Deserialize, Serialize)] struct Foo { #[serde( deserialize_with = "serde_with::rust::display_fromstr::deserialize", serialize_with = "serde_with::json::nested::serialize" )] bar: u8, }
However, this will prohibit you from applying deserialize on the value returned by serializing a struct.
Modules
chrono |
De/Serialization of chrono types |
json |
De/Serialization of JSON |
rust |
De/Serialization for Rust's builtin and std types |
Structs
CommaSeparator |
Predefined seperator using a single comma |
SpaceSeparator |
Predefined seperator using a single space |
Traits
Separator |
Seperator for string-based collection de/serialization |