Skip to main content

MemStore

Struct MemStore 

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

An in-memory WalStore backed by a Vec<u8> behind a short lock.

Everything a FileStore does, without touching the filesystem, including the sparse-file behaviour of zero-filling a gap when a higher offset is written first. sync is a no-op — memory has no separate durable tier — so a MemStore is for tests, examples, and benchmarking the framing path in isolation, not for durability.

§Examples

use wal_db::{MemStore, Wal};

let wal = Wal::with_store(MemStore::new())?;
let lsn = wal.append(b"in memory")?;
assert_eq!(lsn.get(), 0);

Implementations§

Source§

impl MemStore

Source

pub fn new() -> Self

Create an empty in-memory store.

Source

pub fn with_capacity(capacity: usize) -> Self

Create an empty store that has pre-allocated room for capacity bytes, to avoid reallocations during a known-size workload.

Source

pub fn from_bytes(bytes: Vec<u8>) -> Self

Create a store preloaded with bytes — for example a log image captured elsewhere, so Wal::with_store can recover it.

Trait Implementations§

Source§

impl Clone for MemStore

Source§

fn clone(&self) -> Self

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 MemStore

Source§

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

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

impl Default for MemStore

Source§

fn default() -> MemStore

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

impl WalStore for MemStore

Source§

fn write_at(&self, offset: u64, bytes: &[u8]) -> Result<()>

Write bytes at byte offset, growing the store and zero-filling any gap if offset is beyond the current end.
Source§

fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize>

Read into buf starting at byte offset, returning the number of bytes read. Read more
Source§

fn truncate(&self, len: u64) -> Result<()>

Discard every byte at or after len, shrinking the store to exactly len bytes.
Source§

fn sync(&self) -> Result<()>

Flush every preceding write_at to stable storage. Read more
Source§

fn len(&self) -> Result<u64>

The current size of the store in bytes.
Source§

fn is_empty(&self) -> Result<bool>

Whether the store holds no bytes. Read more
Source§

fn head(&self) -> Result<u64>

The lowest offset that still holds data. Read more
Source§

fn truncate_before(&self, _offset: u64) -> Result<u64>

Discard storage entirely below offset, if the backend can, returning the new head. 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.
Source§

impl<E> WithErrorCode<E> for E

Source§

fn with_code(self, code: impl Into<String>) -> CodedError<E>

Attach an error code to an error