serde_with v1.9.0
Added
-
Added
FromInto
andTryFromInto
adapters, which enable serialization by converting into a proxy type.// Rust #[serde_as(as = "FromInto<(u8, u8, u8)>")] value: Rgb, impl From<(u8, u8, u8)> for Rgb { ... } impl From<Rgb> for (u8, u8, u8) { ... } // JSON "value": [128, 64, 32],
-
New
serde_conv!
macro to create conversion types with reduced boilerplate.
The generated types can be used with#[serde_as]
or serde's with-attribute.serde_with::serde_conv!( RgbAsArray, Rgb, |rgb: &Rgb| [rgb.red, rgb.green, rgb.blue], |value: [u8; 3]| -> Result<_, std::convert::Infallible> { Ok(Rgb { red: value[0], green: value[1], blue: value[2], }) } );