pub struct FixedIdGenerator<Id>(pub Id);Expand description
An IdGenerator that always returns the same, fixed id.
§Examples
use ddd_toolkit_core::domain::{EntityId, ValueObject};
use ddd_toolkit_core::mock::id::FixedIdGenerator;
use ddd_toolkit_core::port::id::IdGenerator;
use std::fmt::Display;
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
struct OrderId(u32);
impl ValueObject for OrderId {}
impl Display for OrderId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "order-{}", self.0)
}
}
impl EntityId for OrderId {}
// useful in a test that needs a predictable id to assert against
let generator = FixedIdGenerator(OrderId(1));
assert_eq!(generator.generate(), OrderId(1));
assert_eq!(generator.generate(), OrderId(1));Tuple Fields§
§0: IdTrait Implementations§
Source§impl<Id: Clone> Clone for FixedIdGenerator<Id>
impl<Id: Clone> Clone for FixedIdGenerator<Id>
Source§fn clone(&self) -> FixedIdGenerator<Id>
fn clone(&self) -> FixedIdGenerator<Id>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Id: Debug> Debug for FixedIdGenerator<Id>
impl<Id: Debug> Debug for FixedIdGenerator<Id>
Source§impl<Id: EntityId> IdGenerator<Id> for FixedIdGenerator<Id>
impl<Id: EntityId> IdGenerator<Id> for FixedIdGenerator<Id>
Auto Trait Implementations§
impl<Id> Freeze for FixedIdGenerator<Id>where
Id: Freeze,
impl<Id> RefUnwindSafe for FixedIdGenerator<Id>where
Id: RefUnwindSafe,
impl<Id> Send for FixedIdGenerator<Id>where
Id: Send,
impl<Id> Sync for FixedIdGenerator<Id>where
Id: Sync,
impl<Id> Unpin for FixedIdGenerator<Id>where
Id: Unpin,
impl<Id> UnsafeUnpin for FixedIdGenerator<Id>where
Id: UnsafeUnpin,
impl<Id> UnwindSafe for FixedIdGenerator<Id>where
Id: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more