pub struct MemoryStore { /* private fields */ }server only.Expand description
A ResourceStore holding everything in a Vec per collection.
Cheap to clone — clones share one store, which is what lets a test seed
through one handle and read through another. It is what
MockTmfServer is built on, and it is a
reasonable place to start a real server before there is a database to point
at.
use rutmf::server::MemoryStore;
let store = MemoryStore::new();
store.seed("productOffering", serde_json::json!({"id": "7655"}));
assert_eq!(store.collection("productOffering").len(), 1);Implementations§
Source§impl MemoryStore
impl MemoryStore
Sourcepub fn seed(&self, collection: &str, resource: Value)
pub fn seed(&self, collection: &str, resource: Value)
Adds a resource to collection without going through the API.
Nothing is validated and no id is assigned: this puts the store into a known state, which is what a test wants.
Sourcepub fn seed_all(
&self,
collection: &str,
resources: impl IntoIterator<Item = Value>,
)
pub fn seed_all( &self, collection: &str, resources: impl IntoIterator<Item = Value>, )
Adds several resources to collection.
Sourcepub fn collection(&self, collection: &str) -> Vec<Value>
pub fn collection(&self, collection: &str) -> Vec<Value>
Everything held in collection, in insertion order.
Trait Implementations§
Source§impl Clone for MemoryStore
impl Clone for MemoryStore
Source§impl Debug for MemoryStore
impl Debug for MemoryStore
Source§impl Default for MemoryStore
impl Default for MemoryStore
Source§impl ResourceStore for MemoryStore
impl ResourceStore for MemoryStore
Source§fn replace_if_unchanged<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
resource: Value,
expected_tag: &'life3 str,
) -> Pin<Box<dyn Future<Output = StoreResult<Replaced>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn replace_if_unchanged<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
resource: Value,
expected_tag: &'life3 str,
) -> Pin<Box<dyn Future<Output = StoreResult<Replaced>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Compares and writes under one lock, so If-Match is a real precondition.
The default implementation reads, compares and writes as three separate steps; here the mutex is held across all three, which is what closes the lost-update window rather than merely narrowing it.
Source§fn delete_if_unchanged<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
expected_tag: &'life3 str,
) -> Pin<Box<dyn Future<Output = StoreResult<Replaced>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn delete_if_unchanged<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
expected_tag: &'life3 str,
) -> Pin<Box<dyn Future<Output = StoreResult<Replaced>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
The delete half of replace_if_unchanged,
likewise under one lock.
Source§fn list<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
selection: &'life2 Selection,
) -> Pin<Box<dyn Future<Output = StoreResult<Matched>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn list<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
selection: &'life2 Selection,
) -> Pin<Box<dyn Future<Output = StoreResult<Matched>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
) -> Pin<Box<dyn Future<Output = StoreResult<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
) -> Pin<Box<dyn Future<Output = StoreResult<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Ok(None) if there is no such resource.Source§fn create<'life0, 'life1, 'async_trait>(
&'life0 self,
collection: &'life1 str,
resource: Value,
) -> Pin<Box<dyn Future<Output = StoreResult<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn create<'life0, 'life1, 'async_trait>(
&'life0 self,
collection: &'life1 str,
resource: Value,
) -> Pin<Box<dyn Future<Output = StoreResult<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn replace<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
resource: Value,
) -> Pin<Box<dyn Future<Output = StoreResult<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn replace<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
resource: Value,
) -> Pin<Box<dyn Future<Output = StoreResult<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
) -> Pin<Box<dyn Future<Output = StoreResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
collection: &'life1 str,
id: &'life2 str,
) -> Pin<Box<dyn Future<Output = StoreResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
id, reporting whether there was one.