Releases: jonasbb/serde_with
serde_with v1.9.4
Fixed
-
with_prefix!
now supports an optional visibility modifier. (#327, #328)
If not specifiedpub(self)
is assumed.with_prefix!(prefix_active "active_"); // => mod {...} with_prefix!(pub prefix_active "active_"); // => pub mod {...} with_prefix!(pub(crate) prefix_active "active_"); // => pub(crate) mod {...} with_prefix!(pub(in other_mod) prefix_active "active_"); // => pub(in other_mod) mod {...}
Thanks to @elpiel for raising and fixing the issue.
serde_with v1.9.3
Added
-
The
Bytes
type now supports borrowed and Cow arrays of fixed size (requires Rust 1.51+)#[serde_as(as = "Bytes")] #[serde(borrow)] borrowed_array: &'a [u8; 15], #[serde_as(as = "Bytes")] #[serde(borrow)] cow_array: Cow<'a, [u8; 15]>,
Note: For borrowed arrays the used Deserializer needs to support Serde's 0-copy deserialization.
serde_with v1.9.2
Fixed
- Suppress clippy warnings, which can occur while using
serde_conv
(#320)
Thanks to @mkroening for reporting and fixing the issue.
serde_with_macros v1.4.2
Fixed
- Describe how the
serde_as
macro works on a high level. - The derive macros
SerializeDisplay
andDeserializeFromStr
were relying on the prelude where they were used.
Properly name all types and traits required for the expanded code to work.
The tests were improved to be better able to catch such problems.
serde_with v1.9.1
Changed
NoneAsEmptyString
: Deserialize usingFromStr
instead of usingfor<'a> From<&'a str>
(#316)
This will not change any behavior when applied to a field of typeOption<String>
as used in the documentation.
Thanks to @mkroening for finding and fixing the issue.
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], }) } );
serde_with v1.8.1
Added
- The
hex::Hex
type also works for u8-arrays on Rust 1.48.
Thanks to @TheAlgorythm for raising and fixing the issue.
serde_with v1.8.0
Added
-
Added
PickFirst
adapter forserde_as
. #291
It allows to deserialize from multiple different forms.
Deserializing a number from either a number or string can be implemented like:#[serde_as(as = "PickFirst<(_, DisplayFromStr)>")] value: u32,
-
Implement
SerializeAs
/DeserializeAs
for more wrapper types. #288, #293
This now supports:Arc
,sync::Weak
Rc
,rc::Weak
Cell
,RefCell
Mutex
,RwLock
Result
Changed
- Add a new
serde_with::rust::map_as_tuple_list
module as a replacement forserde_with::rust::btreemap_as_tuple_list
andserde_with::rust::hashmap_as_tuple_list
.
The new module usesIntoIterator
andFromIterator
as trait bound making it usable in more sitations.
The old names continue to exist but are marked as deprecated.
Deprecated
- Deprecated the module names
serde_with::rust::btreemap_as_tuple_list
andserde_with::rust::hashmap_as_tuple_list
.
You can useserde_with::rust::map_as_tuple_list
as a replacement.
Fixed
serde_with v1.7.0
Added
-
Add support for arrays of arbitrary size. (#272)
This feature requires Rust 1.51+.// Rust #[serde_as(as = "[[_; 64]; 33]")] value: [[u8; 64]; 33], // JSON "value": [[0,0,0,0,0,...], [0,0,0,...], ...],
Mapping of arrays was available before, but limited to arrays of length 32.
All conversion methods are available for the array elements.This is similar to the existing
serde-big-array
crate with three important improvements:- Support for the
serde_as
annotation. - Supports non-copy elements (see serde-big-array#6).
- Supports arbitrary nestings of arrays (see serde-big-array#7).
- Support for the
-
Arrays with tuple elements can now be deserialized from a map. (#272)
This feature requires Rust 1.51+.// Rust #[serde_as(as = "BTreeMap<_, _>")] value: [(String, u16); 3], // JSON "value": { "a": 1, "b": 2, "c": 3 },
-
The
Bytes
type is heavily inspired byserde_bytes
and ports it to theserde_as
system. (#277)#[serde_as(as = "Bytes")] value: Vec<u8>,
Compared to
serde_bytes
these improvements are available- Integration with the
serde_as
annotation (see serde-bytes#14). - Implementation for arrays of arbitrary size (Rust 1.51+) (see serde-bytes#26).
- Integration with the
-
The
OneOrMany
allows to deserialize aVec
from either a single element or a sequence. (#281)#[serde_as(as = "OneOrMany<_>")] cities: Vec<String>,
This allows to deserialize from either
cities: "Berlin"
orcities: ["Berlin", "Paris"]
.
The serialization can be configured to always emit a list withPreferMany
or emit a single element withPreferOne
.
serde_with v1.6.4
Fixed
- Fix compiling when having a struct field without the
serde_as
annotation by updatingserde_with_macros
.
This broke in 1.4.0 ofserde_with_macros
. #267