Struct esrs::AggregateState
source · pub struct AggregateState<S> { /* private fields */ }
Expand description
The internal state for an Aggregate. It contains:
- an id uniquely representing the aggregate,
- an incremental sequence number,
- a lock representing the atomicity of the access to the aggregate,
- a state defined by the user of this library.
Implementations§
source§impl<S: Default> AggregateState<S>
impl<S: Default> AggregateState<S>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of an AggregateState
with a new unique id.
sourcepub fn with_id(id: impl Into<Uuid>) -> Self
pub fn with_id(id: impl Into<Uuid>) -> Self
Creates a new instance of an AggregateState
with the given aggregate id.
This should be used almost exclusively when loading by aggregate id yields nothing, and this becomes the brand new aggregate state for that id.
Other uses are strongly discouraged, since the id could be already existing and a clash might happen when persisting events.
sourcepub fn apply_store_events<T, F>(
self,
store_events: Vec<StoreEvent<T>>,
apply_event: F
) -> Selfwhere
F: Fn(S, T) -> S,
pub fn apply_store_events<T, F>(
self,
store_events: Vec<StoreEvent<T>>,
apply_event: F
) -> Selfwhere
F: Fn(S, T) -> S,
Consumes the aggregate state and generates a new one with the events applied to it,
as dictated by apply_event
.
sourcepub fn into_inner(self) -> S
pub fn into_inner(self) -> S
Consumes self and extracts the internal state.
sourcepub const fn sequence_number(&self) -> &SequenceNumber
pub const fn sequence_number(&self) -> &SequenceNumber
Returns the internal sequence number.
sourcepub fn next_sequence_number(&mut self) -> SequenceNumber
pub fn next_sequence_number(&mut self) -> SequenceNumber
Computes the internal sequence number incremented by 1.
sourcepub fn set_lock(&mut self, guard: EventStoreLockGuard)
pub fn set_lock(&mut self, guard: EventStoreLockGuard)
Inserts the lock guard into self, replacing any current one.
sourcepub fn take_lock(&mut self) -> Option<EventStoreLockGuard>
pub fn take_lock(&mut self) -> Option<EventStoreLockGuard>
Extracts the lock from self, leaving nothing behind.
Trait Implementations§
source§impl<S: Debug> Debug for AggregateState<S>
impl<S: Debug> Debug for AggregateState<S>
source§impl<S: Default> Default for AggregateState<S>
impl<S: Default> Default for AggregateState<S>
Default implementation for AggregateState
Auto Trait Implementations§
impl<S> Freeze for AggregateState<S>where
S: Freeze,
impl<S> !RefUnwindSafe for AggregateState<S>
impl<S> Send for AggregateState<S>where
S: Send,
impl<S> Sync for AggregateState<S>where
S: Sync,
impl<S> Unpin for AggregateState<S>where
S: Unpin,
impl<S> !UnwindSafe for AggregateState<S>
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more