pub struct InMemoryDataService<T: Data> { /* private fields */ }Expand description
In-memory implementation of DataService
Provides a generic in-memory store for any entity type implementing Data.
Useful for testing, development, and prototyping without external dependencies.
Uses Arc<RwLock<HashMap>> for thread-safe concurrent access.
§Example
ⓘ
use this::storage::InMemoryDataService;
let service = InMemoryDataService::<MyEntity>::new();
let entity = service.create(my_entity).await?;
let found = service.get(&entity.id()).await?;Implementations§
Trait Implementations§
Source§impl<T: Data> Clone for InMemoryDataService<T>
impl<T: Data> Clone for InMemoryDataService<T>
Source§impl<T: Data> DataService<T> for InMemoryDataService<T>
impl<T: Data> DataService<T> for InMemoryDataService<T>
Source§fn create<'life0, 'async_trait>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create<'life0, 'async_trait>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Create a new entity
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get an entity by ID
Source§fn list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List all entities
Source§fn update<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Uuid,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Uuid,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Update an existing entity
Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Uuid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 Uuid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete an entity
Source§fn search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
field: &'life1 str,
value: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
field: &'life1 str,
value: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Search entities by field values
Auto Trait Implementations§
impl<T> Freeze for InMemoryDataService<T>
impl<T> RefUnwindSafe for InMemoryDataService<T>
impl<T> Send for InMemoryDataService<T>
impl<T> Sync for InMemoryDataService<T>
impl<T> Unpin for InMemoryDataService<T>
impl<T> UnsafeUnpin for InMemoryDataService<T>
impl<T> UnwindSafe for InMemoryDataService<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