serde_with icon indicating copy to clipboard operation
serde_with copied to clipboard

Wishlist: Blocked on upstream changes

Open jonasbb opened this issue 2 years ago • 0 comments

  • MSRV Rust 1.64:

    • Use workspace.package and workspace.dependencies. The main advantage is sharing the metadata between the related packages. The slightly simpler dependency management is a bonus.
  • MSRV Rust 1.88:

    • Replace cfg(all()) and cfg(any()) with cfg(true) and cfg(false)
  • feature(adt_const_params)

    • Add extra layers for serializing/deserializing. https://github.com/jonasbb/serde_with/issues/340#issuecomment-961492301

      ![feature(adt_const_params)]
      
      [derive(Copy, Clone, Debug, Default)]
      ub struct Layer<const FIELD: &'static str, T: ?Sized>(T);
      
      mpl<const FIELD: &'static str, T, U> SerializeAs<T> for Layer<FIELD, U>
      here
         U: SerializeAs<T>,
         T: ?Sized,
         U: ?Sized,
      
         fn serialize_as<S>(source: &T, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
             use serde::ser::SerializeStruct;
      
             let mut ser_struct = serializer.serialize_struct("Layer", 1)?;
             ser_struct.serialize_field(FIELD, &ser::SerializeAsWrap::<T, U>::new(source))?;
             ser_struct.end()
         }
      
      
      / Can be used like this
      [serde_as]
      [derive(Serialize)]
      truct Data {
         i: i32,
         #[serde_as(as = r#"Layer<"extra", Layer<"foobar", Layer<"really_another_one", DisplayFromStr>>>"#)]
         b: bool,
      
      
      / or like
      erde_json::to_string(&Layer::<"root">(&data))
      

      https://github.com/dtolnay/monostate contains a solution to encode &str into a static type without requiring adt_const_params. It doesn't quite fit the above use case, since the value is not accessible as a &'static str. But Layer could be implemented if it uses serialize_map.

    • Add a macro-free version of with_prefix!.

    • Get rid of the special key name requirement for `KeyValueMap https://github.com/jonasbb/serde_with/blob/725d177fdf66583fc234ca07e2ec8df4a03c1aa4/serde_with/src/key_value_map.rs#L210-L215

  • feature(array_try_from_fn) https://github.com/rust-lang/rust/issues/89379

    • Replace the unsafe implementation of array_from_iterator with something from std. https://github.com/rust-lang/rust/issues/81615 https://github.com/jonasbb/serde_with/blob/b50b611b690aeb2747030b90b7c10e921ffb2ec4/serde_with/src/utils.rs#L119-L174
  • Use workspace lints with separate overrides per crate: https://github.com/rust-lang/cargo/issues/13157

  • feature(core_float_math) https://github.com/rust-lang/rust/issues/137578 https://github.com/jonasbb/serde_with/blob/be794b7f89683f1adc9e508f199f0822267f2d47/serde_with/src/utils/duration.rs#L389-L399

    Currently, for deserializing Durations as f64 the values are rounded. The round() function is only available in std, thus the implementations must be gated. Writing a rounding function that works well for all f64 values is also not trivial.

jonasbb avatar Mar 04 '23 20:03 jonasbb