Skip to content

Releases: jonasbb/serde_with

serde_with v1.11.0

18 Oct 20:07
0243453
Compare
Choose a tag to compare

Added

  • Serialize bytes as base64 encoded strings.
    The character set and padding behavior can be configured.

    // Rust
    #[serde_as(as = "serde_with::base64::Base64")]
    value: Vec<u8>,
    #[serde_as(as = "Base64<Bcrypt, Unpadded>")]
    bcrypt_unpadded: Vec<u8>,
    
    // JSON
    "value": "SGVsbG8gV29ybGQ=",
    "bcrypt_unpadded": "QETqZE6eT07wZEO",
  • The minimal supported Rust version (MSRV) is now specified in the Cargo.toml via the rust-version field. The field is supported in Rust 1.56 and has no effect on versions before.

    More details: https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field

Fixed

  • Fixed RUSTSEC-2020-0071 in the time v0.1 dependency, but changing the feature flags of the chrono dependency. This should not change anything. Crates requiring the oldtime feature of chrono can enable it separately.

serde_with_macros v1.5.1

18 Oct 20:07
0243453
Compare
Choose a tag to compare

Added

serde_with v1.10.0

04 Sep 20:30
4087080
Compare
Choose a tag to compare

Added

  • Add BorrowCow which instructs serde to borrow data during deserialization of Cow<'_, str>, Cow<'_, [u8]>, or Cow<'_, [u8; N]>. (#347)
    The implementation is for serde#2072 and serde#2016, about #[serde(borrow)] not working for Option<Cow<'a, str>>.

    #[serde_as]
    #[derive(Deserialize, Serialize)]
    struct Data<'a> {
        #[serde_as(as = "Option<[BorrowCow; 1]>")]
        nested: Option<[Cow<'a, str>; 1]>,
    }

    The #[serde(borrow)] annotation is automatically added by the #[serde_as] attribute.

Changed

  • Bump MSRV to 1.46, since the dev-dependency bitflags requires that version now.
  • flattened_maybe! no longer requires the serde_with crate to be available with a specific name.
    This allows renaming the crate or using flattened_maybe! through a re-export without any complications.

serde_with_macros v1.5.0

04 Sep 20:28
4087080
Compare
Choose a tag to compare

Added

  • Add the attribute #[serde(borrow)] on a field if serde_as is used in combination with the BorrowCow type.

serde_with v1.9.4

18 Jun 16:46
7dca3d2
Compare
Choose a tag to compare

Fixed

  • with_prefix! now supports an optional visibility modifier. (#327, #328)
    If not specified pub(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

14 Jun 20:04
42225c4
Compare
Choose a tag to compare

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

07 Jun 19:23
115de87
Compare
Choose a tag to compare

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

07 Jun 19:20
115de87
Compare
Choose a tag to compare

Fixed

  • Describe how the serde_as macro works on a high level.
  • The derive macros SerializeDisplay and DeserializeFromStr 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

15 May 17:04
fc2db96
Compare
Choose a tag to compare

Changed

  • NoneAsEmptyString: Deserialize using FromStr instead of using for<'a> From<&'a str> (#316)
    This will not change any behavior when applied to a field of type Option<String> as used in the documentation.
    Thanks to @mkroening for finding and fixing the issue.

serde_with v1.9.0

09 May 14:38
e90d7f4
Compare
Choose a tag to compare

Added

  • Added FromInto and TryFromInto 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],
            })
        }
    );