#[derive(IdZst)]
{
// Attributes available to this derive:
#[ruma_id]
}
Expand description
Generate methods and trait impl’s for ZST 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
,AsRef
andBorrow
to the borrowed type for the owned type.PartialEq
implementations 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 implementFrom
string types, when this is set they implementTryFrom
.
§Examples
ⓘ
use ruma_macros::IdZst;
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, IdZst)]
#[ruma_id(validate = ruma_identifiers_validation::user_id::validate)]
pub struct UserId(str);