#[entity_id]Expand description
Turn a single-field tuple struct into a fully-featured entity-ID newtype.
Applied to struct Foo(Inner); (exactly one unnamed field), this macro
generates the standard derive set plus the conversions and helpers users
expect from a strongly-typed identifier:
- Default derives:
Default,Clone,Copy,serde::Serialize,serde::Deserialize,PartialEq,Eq,Hash, and (by default)Debug. User-supplied derives are merged in. pub fn new(value: Inner) -> Selfimpl FromStr(forwarding to the inner type’sFromStr).impl Display(forwarding to the inner type’sDisplay).impl AsRef<Inner>andimpl AsMut<Inner>.impl From<Inner>/impl From<&Inner>and the symmetricimpl From<Self>/impl From<&Self> for Innerconversions.
§Attribute arguments
#[entity_id(debug = <bool>)]
debug— disable the auto-derivedDebug(defaults totrue) so callers can hand-write a redacting or otherwise customised impl.
§Important
Because the macro derives Copy, the inner type must implement
Copy (e.g. Uuid, u64, i64). Wrappers around String are not
supported through this macro.
§Examples
ⓘ
use eventide_macros::entity_id;
use uuid::Uuid;
#[entity_id]
struct OrderId(Uuid);
let id = OrderId::new(Uuid::new_v4());
let copy = id; // `Copy` works.
let _ = format!("{} / {:?}", id, id); // `Display` and `Debug` both work.Custom Debug impl:
ⓘ
use eventide_macros::entity_id;
use uuid::Uuid;
#[entity_id(debug = false)]
struct ProfileId(Uuid);
impl std::fmt::Debug for ProfileId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ProfileId(<redacted>)")
}
}