Skip to main content

MemoryBackend

Struct MemoryBackend 

Source
pub struct MemoryBackend { /* private fields */ }
Expand description

In-memory bytes backend backed by parking_lot::Mutex<HashMap<String, Vec<u8>>>. All operations are synchronous and in-process. Useful for tests, hot tiers, and as the default backend for the memory_* convenience factories.

Default uses "memory" as the diagnostic name; use Self::with_name to set a different one (the per-tier-name pattern from the TS impl — helps disambiguate multiple in-process tiers in diagnostics).

Implementations§

Source§

impl MemoryBackend

Source

pub fn new() -> Self

Source

pub fn with_name(name: impl Into<String>) -> Self

Source

pub fn len(&self) -> usize

Diagnostic helper: number of keys currently stored.

Source

pub fn is_empty(&self) -> bool

Diagnostic helper: whether the backend holds any keys.

Trait Implementations§

Source§

impl Debug for MemoryBackend

Source§

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

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

impl Default for MemoryBackend

Source§

fn default() -> Self

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

impl StorageBackend for MemoryBackend

Source§

fn name(&self) -> &str

Diagnostic name (e.g. "memory", "file:./checkpoints"). Surfaces in error messages and tier Display impls.
Source§

fn read(&self, key: &str) -> Result<Option<Vec<u8>>, StorageError>

Read raw bytes; returns Ok(None) on miss.
Source§

fn write(&self, key: &str, bytes: &[u8]) -> Result<(), StorageError>

Write raw bytes.
Source§

fn delete(&self, key: &str) -> Result<(), StorageError>

Optional delete-by-key. Default is no-op so append-only or read-only backends can stay quiet.
Source§

fn list(&self, prefix: &str) -> Result<Vec<String>, StorageError>

Enumerate keys matching prefix (lex-ASC). Empty prefix enumerates all keys. Default returns BackendNoListSupport — backends that don’t support enumeration surface the diagnostic here at first call, NOT at attach (mirrors TS lazy-throw semantics for list_by_prefix).
Source§

fn flush(&self) -> Result<(), StorageError>

Optional drain hook — adapter authors implement when buffering writes. Default no-op; tier flush() does NOT cascade into this by default (the tier owns its own buffer; backend buffering is a separate concern the backend author opts into).

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.