ruma

Module 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.

Modules§

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

Structs§

Base64
A wrapper around B (usually Vec<u8>) that (de)serializes from / to a base64 string.
Base64DecodeError
An error that occurred while decoding a base64 string.
Raw
A wrapper around Box<RawValue> with a generic parameter for the expected Rust type.

Traits§

CanBeEmpty
Trait for types that have an “empty” state.

Functions§

btreemap_deserialize_v1_powerlevel_values
Take a BTreeMap with values of either an integer number or a string and deserialize those to integer numbers.
default_true
Simply returns true.
deserialize_as_number_or_string
Take either a floating point number or a string and deserialize to an floating-point number.
deserialize_as_optional_number_or_string
Deserializes an Option<f64> from an encoded f64 or string or integer (i64 or u64).
deserialize_cow_str
Deserialize a Cow<'de, str>.
deserialize_v1_powerlevel
Take either an integer number or a string and deserialize to an integer number.
empty_string_as_none
Serde deserialization decorator to map empty Strings to None, and forward non-empty Strings to the Deserialize implementation for T.
from_raw_json_value
Helper function for serde_json::value::RawValue deserialization.
is_default
Check whether a value is equal to its default value.
is_empty
Check whether a value is empty.
is_true
Simply dereferences the given bool.
json_to_buf
Creates a buffer and writes a serializable value to it.
none_as_default
Deserialize a T via Option<T>, falling back to T::default().
none_as_empty_string
Serde serializiation decorator to map None to an empty String, and forward Somes to the Serialize implementation for T.
slice_to_buf
Converts a byte slice to a buffer by copying.

Type Aliases§

JsonObject
The inner type of JsonValue::Object.

Derive Macros§

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