#[derive(EntityId)]
{
// Attributes available to this derive:
#[vo]
}
Expand description
Derives EntityId - and everything
#[derive(ValueObject)] derives - for a
single-field tuple struct.
On top of the ValueObject bundle, this adds Eq, Hash, Ord, and
PartialOrd, all delegating to the wrapped field - two ids compare and
hash equal exactly when their inner values do. That makes the result
usable as a HashMap/HashSet key or in a sorted collection, which is
the common case for an identifier type.
See derive_value_object for the shared requirements (single-field
tuple struct, non-pub field) and #[vo(...)] attributes (validate,
no_display) - both apply here unchanged, and rename_all/zeroize
are rejected for the same reasons.
ยงExamples
use ddd_toolkit_core::domain::Wrapped;
use ddd_toolkit_macro::EntityId;
use std::collections::HashSet;
#[derive(EntityId, Clone, PartialEq, Debug)]
struct UserId(u64);
let a = UserId::try_from(1)?;
let b = UserId::try_from(2)?;
assert!(a < b);
let ids: HashSet<UserId> = HashSet::from([UserId::try_from(1)?, UserId::try_from(1)?]);
assert_eq!(ids.len(), 1, "equal inner values dedupe to one id");