Skip to main content

InMemoryStore

Struct InMemoryStore 

Source
pub struct InMemoryStore<A>
where A: AggregateRoot,
{ /* private fields */ }
Expand description

A Load/Save/Delete implementation backed by an in-memory HashMap, with last-write-wins semantics (see Save’s docs for what that means for PortErrorKind::Conflict).

Implementations§

Source§

impl<A> InMemoryStore<A>
where A: AggregateRoot,

Source

pub fn new() -> InMemoryStore<A>

Creates a new, empty store.

Source

pub fn take_recorded_events(&self) -> Vec<<A as AggregateRoot>::Event>

Returns and clears every event recorded by a save call so far.

Source

pub fn len(&self) -> usize

The number of aggregates currently stored.

Source

pub fn is_empty(&self) -> bool

Whether the store currently holds no aggregates.

Trait Implementations§

Source§

impl<A> Debug for InMemoryStore<A>
where A: Debug + AggregateRoot,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<A> Default for InMemoryStore<A>
where A: AggregateRoot,

Source§

fn default() -> InMemoryStore<A>

Returns the “default value” for a type. Read more
Source§

impl<A> Delete<A> for InMemoryStore<A>
where A: AggregateRoot + Clone,

Source§

async fn delete(&self, id: &<A as Entity>::Id) -> Result<(), PortError>

Deletes the aggregate with the given id. Read more
Source§

impl<A> Load<A> for InMemoryStore<A>
where A: AggregateRoot + Clone,

Source§

async fn load(&self, id: &<A as Entity>::Id) -> Result<Option<A>, PortError>

Returns the aggregate with the given id, or None if it doesn’t exist.
Source§

impl<A> Save<A> for InMemoryStore<A>
where A: AggregateRoot + Clone,

Source§

async fn save(&self, aggregate: &mut A) -> Result<(), PortError>

Persists the aggregate, draining and recording any events it has accumulated via AggregateRoot::take_events. Read more

Auto Trait Implementations§

§

impl<A> !Freeze for InMemoryStore<A>

§

impl<A> RefUnwindSafe for InMemoryStore<A>

§

impl<A> Send for InMemoryStore<A>

§

impl<A> Sync for InMemoryStore<A>

§

impl<A> Unpin for InMemoryStore<A>
where <A as AggregateRoot>::Event: Unpin, <A as Entity>::Id: Unpin, A: Unpin,

§

impl<A> UnsafeUnpin for InMemoryStore<A>

§

impl<A> UnwindSafe for InMemoryStore<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.