pub struct InMemoryStore<T: Clone + Send + Sync> { /* private fields */ }Expand description
Generic in-memory store for entities
This store provides a simple key-value storage with soft delete support. It’s designed for testing and prototyping, not for production use.
§Type Parameters
T: The entity type to store. Must beClone + Send + Sync.
Implementations§
Source§impl<T: Clone + Send + Sync> InMemoryStore<T>
impl<T: Clone + Send + Sync> InMemoryStore<T>
Create a new store wrapped in Arc for sharing across async tasks
Sourcepub async fn get(&self, id: &str) -> Option<T>
pub async fn get(&self, id: &str) -> Option<T>
Get an item by ID (returns None if not found or soft-deleted)
Sourcepub async fn get_deleted(&self, id: &str) -> Option<T>
pub async fn get_deleted(&self, id: &str) -> Option<T>
Get a soft-deleted item by ID
Sourcepub async fn exists_in_trash(&self, id: &str) -> bool
pub async fn exists_in_trash(&self, id: &str) -> bool
Check if an item exists in trash
Sourcepub async fn update(&self, id: &str, item: T) -> Option<T>
pub async fn update(&self, id: &str, item: T) -> Option<T>
Update an existing item (returns None if not found)
Sourcepub async fn soft_delete(&self, id: &str) -> bool
pub async fn soft_delete(&self, id: &str) -> bool
Soft delete an item (move to trash)
Sourcepub async fn hard_delete(&self, id: &str) -> Option<T>
pub async fn hard_delete(&self, id: &str) -> Option<T>
Permanently delete an item from trash
Sourcepub async fn empty_trash(&self) -> u64
pub async fn empty_trash(&self) -> u64
Empty the trash (permanently delete all soft-deleted items)
Sourcepub async fn list_deleted(&self, page: u32, limit: u32) -> (Vec<T>, u64)
pub async fn list_deleted(&self, page: u32, limit: u32) -> (Vec<T>, u64)
List soft-deleted items with pagination
Sourcepub async fn all_deleted(&self) -> Vec<T>
pub async fn all_deleted(&self) -> Vec<T>
Get all soft-deleted items
Sourcepub async fn trash_count(&self) -> u64
pub async fn trash_count(&self) -> u64
Get the count of soft-deleted items
Sourcepub async fn clear_active(&self)
pub async fn clear_active(&self)
Clear only active items
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for InMemoryStore<T>
impl<T> !RefUnwindSafe for InMemoryStore<T>
impl<T> !UnwindSafe for InMemoryStore<T>
impl<T> Send for InMemoryStore<T>
impl<T> Sync for InMemoryStore<T>
impl<T> Unpin for InMemoryStore<T>
impl<T> UnsafeUnpin for InMemoryStore<T>
Blanket Implementations§
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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