#[derive(IdDst)]
{
// Attributes available to this derive:
#[ruma_id]
}
Expand description
Generate methods and trait impl’s for DST identifier type.
This macro generates an Owned* type for the identifier type. The internal representation of
the owned type is variable, by default it’ll use a Box<str>, but it can be changed at compile
time by setting --cfg=ruma_identifiers_storage=... using RUSTFLAGS or .cargo/config.toml
(under [build] -> rustflags = ["..."]). The supported values for this setting are listed in
the docs of the owned type.
This macro implements:
- Conversions to and from string types,
AsRef<[u8]>andAsRef<str>, as well asas_str()andas_bytes()methods. The borrowed type can be converted from a borrowed string without allocation. - Conversions to and from borrowed and owned type.
Deref,AsRefandBorrowto the borrowed type for the owned type.PartialEqimplementations for testing equality with string types and owned and borrowed types.
The type must be a tuple struct with str as its last field, and it must be
#[repr(transparent)], because the generated code converts &str to the borrowed type with
a transmute.
§Attributes
#[ruma_id(validate = PATH)]: the path to a function to validate the string during parsing and deserialization. By default, the types implementFromstring types, when this is set they implementTryFrom.#[ruma_id(smallvec_inline_bytes = USIZE)]: the size of the inline array for theSmallVecinner representation. If this is not provided the default inline size is32.
§Examples
ⓘ
use ruma_macros::IdDst;
#[repr(transparent)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, IdDst)]
#[ruma_id(validate = ruma_identifiers_validation::user_id::validate, smallvec_inline_bytes = 40)]
pub struct UserId(str);