[−][src]Attribute Macro serde_with::serde_as
#[serde_as]
Convenience macro to use the serde_as
system.
The serde_as
system is designed as a more flexible alterative to serde's with-annotation.
Example
ⓘThis example is not tested
use serde_with::{serde_as, DisplayFromStr}; use std::collections::HashMap; #[serde_as] #[derive(Serialize, Deserialize)] struct Data { /// Serialize into number #[serde_as(as = "_")] a: u32, /// Serialize into String #[serde_as(as = "DisplayFromStr")] b: u32, /// Serialize into a map from String to String #[serde_as(as = "HashMap<DisplayFromStr, _>")] c: Vec<(u32, String)>, }
Limitations
This macro cannot be used outside of the serde_with
crate, since it relies on types defined therein.
The serde_with
crate has to be available in the root namespace under ::serde_with
.