pub struct EntityEvents<T: EsEvent> {
pub entity_id: <T as EsEvent>::EntityId,
/* private fields */
}Expand description
A Vec wrapper that manages event-stream of an entity with helpers for event-sourcing operations
Provides event sourcing operations for loading, appending, and persisting events in chronological sequence. Required field for all event-sourced entities to maintain their state change history.
Fields§
§entity_id: <T as EsEvent>::EntityIdThe entity’s id
Implementations§
Source§impl<T> EntityEvents<T>where
T: EsEvent,
impl<T> EntityEvents<T>where
T: EsEvent,
Sourcepub fn init(
id: <T as EsEvent>::EntityId,
initial_events: impl IntoIterator<Item = T>,
) -> Self
pub fn init( id: <T as EsEvent>::EntityId, initial_events: impl IntoIterator<Item = T>, ) -> Self
Initializes a new EntityEvents instance with the given entity ID and initial events which is returned by IntoEvents method
Sourcepub fn entity_first_persisted_at(&self) -> Option<DateTime<Utc>>
pub fn entity_first_persisted_at(&self) -> Option<DateTime<Utc>>
Returns the timestamp of the first persisted event, indicating when the entity was created
Sourcepub fn entity_last_modified_at(&self) -> Option<DateTime<Utc>>
pub fn entity_last_modified_at(&self) -> Option<DateTime<Utc>>
Returns the timestamp of the last persisted event, indicating when the entity was last modified
Sourcepub fn push(&mut self, event: T)
pub fn push(&mut self, event: T)
Appends a single new event to the entity’s event stream to be persisted later
Sourcepub fn extend(&mut self, events: impl IntoIterator<Item = T>)
pub fn extend(&mut self, events: impl IntoIterator<Item = T>)
Appends multiple new events to the entity’s event stream to be persisted later
Sourcepub fn any_new(&self) -> bool
pub fn any_new(&self) -> bool
Returns true if there are any unpersisted events waiting to be saved
Sourcepub fn len_persisted(&self) -> usize
pub fn len_persisted(&self) -> usize
Returns the count of persisted events
Sourcepub fn iter_persisted(
&self,
) -> impl DoubleEndedIterator<Item = &PersistedEvent<T>>
pub fn iter_persisted( &self, ) -> impl DoubleEndedIterator<Item = &PersistedEvent<T>>
Returns an iterator over all persisted events
Sourcepub fn last_persisted(&self, n: usize) -> LastPersisted<'_, T>
pub fn last_persisted(&self, n: usize) -> LastPersisted<'_, T>
Returns an iterator over the last n persisted events
Sourcepub fn iter_all(&self) -> impl DoubleEndedIterator<Item = &T>
pub fn iter_all(&self) -> impl DoubleEndedIterator<Item = &T>
Returns an iterator over all events (both persisted and new) in chronological order
Sourcepub fn load_first<E: EsEntity<Event = T>>(
events: impl IntoIterator<Item = GenericEvent<<T as EsEvent>::EntityId>>,
) -> Result<E, EsEntityError>
pub fn load_first<E: EsEntity<Event = T>>( events: impl IntoIterator<Item = GenericEvent<<T as EsEvent>::EntityId>>, ) -> Result<E, EsEntityError>
Loads and reconstructs the first entity from a stream of GenericEvents, marking events as persisted
Sourcepub fn load_n<E: EsEntity<Event = T>>(
events: impl IntoIterator<Item = GenericEvent<<T as EsEvent>::EntityId>>,
n: usize,
) -> Result<(Vec<E>, bool), EsEntityError>
pub fn load_n<E: EsEntity<Event = T>>( events: impl IntoIterator<Item = GenericEvent<<T as EsEvent>::EntityId>>, n: usize, ) -> Result<(Vec<E>, bool), EsEntityError>
Loads and reconstructs up to n entities from a stream of GenericEvents.
Assumes the events are grouped by id and ordered by sequence per id.
Returns both the entities and a flag indicating whether more entities were available in the stream.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for EntityEvents<T>
impl<T> RefUnwindSafe for EntityEvents<T>
impl<T> Send for EntityEvents<T>
impl<T> Sync for EntityEvents<T>
impl<T> Unpin for EntityEvents<T>
impl<T> UnwindSafe for EntityEvents<T>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)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