Skip to main content

MemoryStore

Struct MemoryStore 

Source
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§

Source§

impl MemoryStore

Source

pub fn new() -> Self

Creates an unbounded in-memory store.

§Returns

An empty store that grows to hold as many records as memory allows.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a store that buffers at most capacity records.

§Arguments
  • capacity - the maximum number of records to buffer; once reached, append reports backpressure instead of growing.
§Returns

An empty capacity-bounded store.

Trait Implementations§

Source§

impl Clone for MemoryStore

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MemoryStore

Source§

fn default() -> MemoryStore

Returns the “default value” for a type. Read more
Source§

impl Store for MemoryStore

Source§

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>>>

Returns the oldest record without removing it. Read more
Source§

async fn pop(&mut self) -> Result<Option<Vec<u8>>>

Removes and returns the oldest record in the queue. Read more
Source§

async fn len(&self) -> Result<usize>

Returns the number of records currently buffered. Read more
Source§

async fn is_empty(&self) -> Result<bool, Error>

Returns whether the queue currently holds no records. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.