Skip to content

v2.0.0

Compare
Choose a tag to compare
@ecton ecton released this 28 Feb 16:36
· 33 commits to main since this release
3d13632

Breaking Changes

  • The format module has been refactored to pass Write by value rather than
    by mutable reference. Most code should not be affected because Write is
    implemented for &mut Write.

Changed

  • The unit type () and Option::None are more fuzzy when deserializing. If
    users deserialize a value that was serialized as None or (), the default
    value will be returned rather than an error, when possible. For example:

    let unit = pot::to_vec(&())?;
    assert_eq!(pot::from_slice(&unit).unwrap(), 0_u32)
    let none = pot::to_vec(&Option::<bool>::None)?;
    assert_eq!(pot::from_slice(&unit).unwrap(), 0_u32)

    This is not practically useful for most users, but when designing traits that
    have associated serializable types, sometimes it's useful to use () when no
    data needs to be stored. However, it can be painful to update existing data
    when switching between () and other types, as Serde offers no built-in
    transmutation. Pot now offers this internally.

Added

  • Value::from_serialize and Value::deserialize_as have been added, allowing
    Value to be transmuted directly from types that implement Serialize and
    Deserialize.
  • OwnedValue is a new-type wrapper around Value<'static> that can be used in
    situations where DeserializeOwned is a requirement. This type is needed
    because Value<'a> can borrow from the source of the deserialization, and
    this flexibility causes lifetime errors when trying to deserialize a
    Value<'static> as DeserializeOwned.