Module ruma_common::serde

source ·
Expand description

(De)serialization helpers for other Ruma crates.

Part of that is a fork of serde_urlencoded, with support for sequences in Deserialize / Serialize structs (e.g. Vec<Something>) that are (de)serialized as field=val1&field=val2.

Re-exports

Modules

  • Transparent base64 encoding / decoding as part of (de)serialization.
  • Helpers for emptiness checks in #[serde(skip_serializing_if)].
  • De-/serialization functions for std::time::Duration objects
  • De-/serialization functions to and from json strings, allows the type to be used as a query string.
  • De-/serialization functions to and from single element sequences.
  • Helpers for tests

Structs

  • A wrapper around Box<RawValue>, to be used in place of any type in the Matrix endpoint definition to allow request and response types to contain that said type represented by the generic argument Ev.

Functions

  • Take a BTreeMap with values of either an integer number or a string and deserialize those to integer numbers.
  • Simply returns true.
  • Take either a floating point number or a string and deserialize to an floating-point number.
  • Deserializes an Option<f64> as encoded as a f64 or a string.
  • Deserialize a Cow<'de, str>.
  • Take either an integer number or a string and deserialize to an integer number.
  • Serde deserialization decorator to map empty Strings to None, and forward non-empty Strings to the Deserialize implementation for T. Useful for the typical “A room with an X event with an absent, null, or empty Y field should be treated the same as a room with no such event.” formulation in the spec.
  • Helper function for serde_json::value::RawValue deserialization.
  • Check whether a value is equal to its default value.
  • Simply dereferences the given bool.
  • Creates a buffer and writes a serializable value to it.
  • Deserialize a T via Option<T>, falling back to T::default().
  • Serde serializiation decorator to map None to an empty String, and forward Somes to the Serialize implementation for T.
  • Converts a byte slice to a buffer by copying.

Type Aliases

Derive Macros

  • Derive the AsRef<str> trait for an enum.
  • Derive the fmt::Debug trait using the AsRef<str> implementation of the type.
  • Derive the Deserialize trait using the From<Cow<str>> implementation of the type.
  • Derive the fmt::Display trait using the AsRef<str> implementation of the type.
  • Derive the From<T: AsRef<str> + Into<Box<str>>> trait for an enum.
  • Derive the Ord trait using the AsRef<str> implementation of the type.
  • Derive the PartialEq trait using the AsRef<str> implementation of the type.
  • Derive the PartialOrd trait using the AsRef<str> implementation of the type.
  • Derive the Serialize trait using the AsRef<str> implementation of the type.
  • Shorthand for the derives AsRefStr, FromString, DisplayAsRefStr, DebugAsRefStr, SerializeAsRefStr and DeserializeFromCowStr.