jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
930 stars 89 forks source link

Consider removing `O` type parameter of `serialize_with_flavor` #103

Open dtolnay opened 1 year ago

dtolnay commented 1 year ago

postcard::serialize_with_flavor is written in an odd way that makes the caller restate the Flavor's Output type explicitly when using turbofish.

https://github.com/jamesmunns/postcard/blob/a0ef8a2f90f53f1c30a554624c187a9672d098c9/src/ser/mod.rs#L367-L370

- pub fn serialize_with_flavor<T, S, O>(value: &T, storage: S) -> Result<O>
+ pub fn serialize_with_flavor<T, S>(value: &T, storage: S) -> Result<S::Output>
  where
      T: Serialize + ?Sized,
-     S: Flavor<Output = O>,
+     S: Flavor,
dtolnay commented 1 year ago

I can't tell whether this was a stylistic choice or oversight. My preference is for serialize_with_flavor::<T, Cobs<Slice<'a>>>(...) over serialize_with_flavor::<T, Cobs<Slice<'a>>, &'a mut [u8]>(...), but I can see there may be valid preferences in the other direction.

jamesmunns commented 1 year ago

As far as I can tell - this was likely an oversight, probably an artifact implementing flavors and never stepping back and realizing that those (always?) are the same type.

I do think this would be a breaking change as you noted in https://github.com/jamesmunns/postcard/pull/105, but I'm tagging it with the 2.0 label so I don't forget to clean this up on the next major release.