#[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* wrapper type for the identifier type. This wrapper type is
variable, by default it’ll use Box, but it can be changed at compile time
by setting --cfg=ruma_identifiers_storage=... using RUSTFLAGS or .cargo/config.toml (under
[build] -> rustflags = ["..."]). Currently the only supported value is Arc, that uses
Arc as a wrapper 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.
§Attributes
#[ruma_api(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.
§Examples
ⓘ
use ruma_macros::IdDst;
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, IdDst)]
#[ruma_id(validate = ruma_identifiers_validation::user_id::validate)]
pub struct UserId(str);