pub struct MemoryStore { /* private fields */ }Expand description
In-memory storage backend.
All data is stored in BTreeMaps — nothing touches disk.
Ideal for testing and prototyping.
§Example
use crdt_store::{MemoryStore, StateStore};
let mut store = MemoryStore::new();
store.put("sensors", "s1", b"temp=22.5").unwrap();
let data = store.get("sensors", "s1").unwrap().unwrap();
assert_eq!(data, b"temp=22.5");Implementations§
Source§impl MemoryStore
impl MemoryStore
Sourcepub fn state_count(&self) -> usize
pub fn state_count(&self) -> usize
Returns the total number of state entries across all namespaces.
Sourcepub fn total_event_count(&self) -> usize
pub fn total_event_count(&self) -> usize
Returns the total number of events across all entities.
Trait Implementations§
Source§impl Default for MemoryStore
impl Default for MemoryStore
Source§impl EventStore for MemoryStore
impl EventStore for MemoryStore
Source§fn append_event(
&mut self,
namespace: &str,
entity_id: &str,
data: &[u8],
timestamp: u64,
node_id: &str,
) -> Result<u64, Self::Error>
fn append_event( &mut self, namespace: &str, entity_id: &str, data: &[u8], timestamp: u64, node_id: &str, ) -> Result<u64, Self::Error>
Append an event to the log for a given entity.
Returns the assigned sequence number.
Source§fn events_since(
&self,
namespace: &str,
entity_id: &str,
since_sequence: u64,
) -> Result<Vec<StoredEvent>, Self::Error>
fn events_since( &self, namespace: &str, entity_id: &str, since_sequence: u64, ) -> Result<Vec<StoredEvent>, Self::Error>
Read events for an entity since a given sequence number (exclusive).
Source§fn event_count(
&self,
namespace: &str,
entity_id: &str,
) -> Result<u64, Self::Error>
fn event_count( &self, namespace: &str, entity_id: &str, ) -> Result<u64, Self::Error>
Count total events for an entity (useful for compaction decisions).
Source§fn save_snapshot(
&mut self,
namespace: &str,
entity_id: &str,
state: &[u8],
at_sequence: u64,
version: u8,
) -> Result<(), Self::Error>
fn save_snapshot( &mut self, namespace: &str, entity_id: &str, state: &[u8], at_sequence: u64, version: u8, ) -> Result<(), Self::Error>
Save a snapshot of an entity’s state at a given event sequence.
Source§impl StateStore for MemoryStore
impl StateStore for MemoryStore
Source§fn put(
&mut self,
namespace: &str,
key: &str,
value: &[u8],
) -> Result<(), Self::Error>
fn put( &mut self, namespace: &str, key: &str, value: &[u8], ) -> Result<(), Self::Error>
Store a value under
(namespace, key).Source§fn get(
&self,
namespace: &str,
key: &str,
) -> Result<Option<Vec<u8>>, Self::Error>
fn get( &self, namespace: &str, key: &str, ) -> Result<Option<Vec<u8>>, Self::Error>
Retrieve a value by
(namespace, key).
Returns None if the key does not exist.Source§fn delete(&mut self, namespace: &str, key: &str) -> Result<(), Self::Error>
fn delete(&mut self, namespace: &str, key: &str) -> Result<(), Self::Error>
Delete a value by
(namespace, key).Auto Trait Implementations§
impl Freeze for MemoryStore
impl RefUnwindSafe for MemoryStore
impl Send for MemoryStore
impl Sync for MemoryStore
impl Unpin for MemoryStore
impl UnwindSafe for MemoryStore
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