pub struct MemoryStore { /* private fields */ }Expand description
A fast in-memory first-in first-out queue.
Records live only for the lifetime of the process, which suits tests, the simulators, and the upper tier of a layered store. An optional capacity caps the number of buffered records and turns a full queue into an explicit backpressure signal rather than letting memory grow without bound.
§Examples
use pamoja_core::Store;
use pamoja_sync::MemoryStore;
let mut store = MemoryStore::new();
store.append(b"first").await?;
store.append(b"second").await?;
assert_eq!(store.len().await?, 2);
assert_eq!(store.pop().await?, Some(b"first".to_vec()));Implementations§
Trait Implementations§
Source§impl Clone for MemoryStore
impl Clone for MemoryStore
Source§fn clone(&self) -> MemoryStore
fn clone(&self) -> MemoryStore
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MemoryStore
impl Debug for MemoryStore
Source§impl Default for MemoryStore
impl Default for MemoryStore
Source§fn default() -> MemoryStore
fn default() -> MemoryStore
Returns the “default value” for a type. Read more
Source§impl Store for MemoryStore
impl Store for MemoryStore
Source§async fn append(&mut self, record: &[u8]) -> Result<()>
async fn append(&mut self, record: &[u8]) -> Result<()>
Appends a record to the back of the queue. Read more
Source§async fn peek(&self) -> Result<Option<Vec<u8>>>
async fn peek(&self) -> Result<Option<Vec<u8>>>
Returns the oldest record without removing it. Read more
Source§async fn pop(&mut self) -> Result<Option<Vec<u8>>>
async fn pop(&mut self) -> Result<Option<Vec<u8>>>
Removes and returns the oldest record in the queue. Read more
Auto Trait Implementations§
impl Freeze for MemoryStore
impl RefUnwindSafe for MemoryStore
impl Send for MemoryStore
impl Sync for MemoryStore
impl Unpin for MemoryStore
impl UnsafeUnpin 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