Skip to main content

Memory

Struct Memory 

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

Memory connection. open(path) is persistent (auto-flushes every apply via atomic write); new() is in-RAM only.

Implementations§

Source§

impl Memory

Source

pub fn new() -> Self

In-RAM memory. Nothing is persisted.

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open (or create) a memory db at path. Reads the file if it exists; otherwise the db starts empty and the file is created on the first write.

Source

pub fn apply(&mut self, op: Op) -> Result<()>

Apply a write op and persist. RAM is mutated before flush, so a flush failure leaves RAM ahead of disk until the next successful op (or the next open, which re-reads the file). WAL will close this window in v2.

Source

pub fn get(&self, name: &str) -> Option<&Entry>

Source

pub fn list(&self) -> impl Iterator<Item = &Entry>

Source

pub fn search(&self, query: &str, limit: usize) -> Vec<SearchHit>

Source

pub fn search_kind( &self, query: &str, limit: usize, kind: EntryKind, ) -> Vec<SearchHit>

BM25 search restricted to a single EntryKind. The inner search runs unbounded so the kind filter can’t truncate matches mid-list; we clone only the survivors that fit inside limit.

Source

pub fn checkpoint(&self) -> Result<()>

Force a write of the current state to disk, whether or not any mutation has happened. Useful for one-shot migration paths that need the db file to exist even when every incoming op failed. A no-op when the memory is in-RAM only (no path).

Source

pub fn dump(&self, dir: impl AsRef<Path>) -> Result<()>

Materialize the db as a markdown tree at dir. Each kind’s subdirectory is cleared before writing so renames and deletes don’t leave orphan files behind. Anything else in dir (e.g. a user’s book.toml) is left alone.

Source

pub fn load(&mut self, dir: impl AsRef<Path>) -> Result<()>

Replace the db’s contents with entries read from a markdown tree at dir. Validates fully before mutating — a mid-load error leaves the current state untouched.

Trait Implementations§

Source§

impl Default for Memory

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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.