Struct InMemoryRepository

Source
pub struct InMemoryRepository<T: AggregateRoot> { /* private fields */ }
Expand description

An in-memory implementation of Repository, using a HashMap.

See the example on Repository for usage information of this repository implementation.

Implementations§

Source§

impl<T: AggregateRoot> InMemoryRepository<T>

Source

pub fn new() -> Self

Creates a new InMemoryRepository.

Trait Implementations§

Source§

impl<T: AggregateRoot> Default for InMemoryRepository<T>

Source§

fn default() -> Self

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

impl<T: AggregateRoot + Clone> ReadRepository<T> for InMemoryRepository<T>
where <T as Entity>::Id: Hash + Eq,

Source§

fn get_by_id<'life0, 'async_trait>( &'life0 self, id: <T as Entity>::Id, ) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets an entity with the given ID.
Source§

fn list<'life0, 'async_trait>( &'life0 self, skip: usize, take: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists all entities within a given page.
Source§

fn count<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns the total number of entities in the repository.
Source§

fn exists<'life0, 'async_trait>( &'life0 self, id: <T as Entity>::Id, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Checks whether an entity with the given ID exists in the repository.
Source§

fn is_empty<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Checks if the repository is empty.
Source§

impl<T: AggregateRoot + Clone> Repository<T> for InMemoryRepository<T>
where <T as Entity>::Id: Hash + Eq,

Source§

fn add<'life0, 'async_trait>( &'life0 self, entity: T, ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Adds an entity to the repository.
Source§

fn update<'life0, 'async_trait>( &'life0 self, entity: T, ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Updates an entity on the repository.
Source§

fn delete<'life0, 'async_trait>( &'life0 self, entity: T, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Deletes the entity from the repository.
Source§

fn add_range<'life0, 'async_trait>( &'life0 self, entities: Vec<T>, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Adds the given entities to the repository.
Source§

fn update_range<'life0, 'async_trait>( &'life0 self, entities: Vec<T>, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Updates the given entities on the repository.
Source§

fn delete_range<'life0, 'async_trait>( &'life0 self, entities: Vec<T>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Deletes the given entities from the repository.

Auto Trait Implementations§

§

impl<T> !Freeze for InMemoryRepository<T>

§

impl<T> RefUnwindSafe for InMemoryRepository<T>

§

impl<T> Send for InMemoryRepository<T>

§

impl<T> Sync for InMemoryRepository<T>

§

impl<T> Unpin for InMemoryRepository<T>
where <T as Entity>::Id: Unpin, T: Unpin,

§

impl<T> UnwindSafe for InMemoryRepository<T>

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.