pub struct MemoryRepository<V: RepositoryItem> {
store: Mutex<HashMap<String, V>>,
}Expand description
A simple in-memory repository implementation. The data is only stored in memory and will not persist beyond the lifetime of the repository instance.
Primary use case is for unit and integration tests.
Fields§
§store: Mutex<HashMap<String, V>>Trait Implementations§
Source§impl<V: RepositoryItem + Clone> Default for MemoryRepository<V>
impl<V: RepositoryItem + Clone> Default for MemoryRepository<V>
Source§impl<V: RepositoryItem + Clone> Repository<V> for MemoryRepository<V>
impl<V: RepositoryItem + Clone> Repository<V> for MemoryRepository<V>
Source§fn get<'life0, 'async_trait>(
&'life0 self,
key: V::Key,
) -> Pin<Box<dyn Future<Output = Result<Option<V>, RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get<'life0, 'async_trait>(
&'life0 self,
key: V::Key,
) -> Pin<Box<dyn Future<Output = Result<Option<V>, RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Retrieves an item from the repository by its key.
Source§fn list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<V>, RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<V>, RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lists all items in the repository.
Source§fn set<'life0, 'async_trait>(
&'life0 self,
key: V::Key,
value: V,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set<'life0, 'async_trait>(
&'life0 self,
key: V::Key,
value: V,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sets an item in the repository with the specified key.
Source§fn set_bulk<'life0, 'async_trait>(
&'life0 self,
values: Vec<(V::Key, V)>,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_bulk<'life0, 'async_trait>(
&'life0 self,
values: Vec<(V::Key, V)>,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sets multiple items in the repository.
Source§fn remove<'life0, 'async_trait>(
&'life0 self,
key: V::Key,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn remove<'life0, 'async_trait>(
&'life0 self,
key: V::Key,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Removes an item from the repository by its key.
Source§fn remove_bulk<'life0, 'async_trait>(
&'life0 self,
keys: Vec<V::Key>,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn remove_bulk<'life0, 'async_trait>(
&'life0 self,
keys: Vec<V::Key>,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Removes multiple items from the repository by their keys.
Source§fn remove_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn remove_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Removes all items from the repository.
§fn replace_all<'life0, 'async_trait>(
&'life0 self,
values: Vec<(<V as RepositoryItem>::Key, V)>,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn replace_all<'life0, 'async_trait>(
&'life0 self,
values: Vec<(<V as RepositoryItem>::Key, V)>,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Replaces all items in the repository with the provided values. This is a convenience method
that first removes all existing items and then sets the new items in bulk. Read more
Auto Trait Implementations§
impl<V> !Freeze for MemoryRepository<V>
impl<V> RefUnwindSafe for MemoryRepository<V>
impl<V> Send for MemoryRepository<V>
impl<V> Sync for MemoryRepository<V>
impl<V> Unpin for MemoryRepository<V>where
V: Unpin,
impl<V> UnsafeUnpin for MemoryRepository<V>
impl<V> UnwindSafe for MemoryRepository<V>
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
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
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
Create a new handle for an Arc value Read more
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
Clone a handle Read more
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Consume a handle, getting back the initial
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
Converts
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>
Converts
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