Skip to main content

SharedMnemo

Struct SharedMnemo 

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

A brain opened in shared mode (12.4): see Mnemo::open_shared.

Every call goes through SharedMnemo::read or SharedMnemo::write, which give the closure the handle for one window on the file:

let mut brain = Mnemo::open_shared("team.mnemo", "passphrase", SharedOptions::default())?;
let id = brain.write(|db| db.remember(Memory::new("we ship on Fridays", MemoryType::Semantic, vec![0.1, 0.2])))?;
let hits = brain.read(|db| db.recall(&RecallRequest::new(vec![0.1, 0.2]).top_k(5)))?;
  • A read runs under the shared lock, on a read-only handle. A recall’s or a cache hit’s access statistics are kept and applied with this handle’s next write; they’re dropped at SharedMnemo::close.
  • A write runs under the exclusive lock and commits before the window ends. If it fails before the commit point, nothing was stored, for a closure that doesn’t commit by itself. A closure that does (it calls flush, or a method that commits, such as commit_deltas or restore_to) and then fails gets MnemoError::MaybeStored, saying part of the window is in the file. If the window’s own commit fails after its commit point, the handle finishes the commit itself and returns Ok, or returns MnemoError::MaybeStored. If the file was renamed away during the commit, MnemoError::ReplacedDuringWrite. Keep to one engine call per window where you can.
  • Access statistics a failed write window applied are dropped when its commit fails; they’re statistics, and the next hits count again.
  • Settings that act on the whole file (snapshot retention, cache budgets, the cache flush policy, turn compression) are refused in v0.14 with MnemoError::Unsupported, and so is rekey inside a closure (use SharedMnemo::rekey, which also updates the secret the handle keeps). The page cache’s size, the vector cache budget and the embedder (however it was set) are kept across reloads.
  • A cancel (SharedMnemo::set_cancel) reaches only a call that is waiting for a lock; once a call holds the lock it runs to its end.

Implementations§

Source§

impl SharedMnemo

Source

pub fn read<R>(&mut self, f: impl FnOnce(&mut Mnemo) -> Result<R>) -> Result<R>

Run f on the handle under the file’s shared lock, after catching up with any other process’s commits. The handle is read-only inside; recall’s default access tracking works and is applied with this handle’s next write.

Source

pub fn write<R>(&mut self, f: impl FnOnce(&mut Mnemo) -> Result<R>) -> Result<R>

Run f on the handle under the file’s exclusive lock, after catching up, and commit before the lock is released. See SharedMnemo for what each failure means.

A closure that commits part of its work itself and then fails, or then changes a setting, gets MnemoError::MaybeStored: the earlier commit is in the file.

Source

pub fn set_author(&mut self, author: Option<String>)

13a: the author stamped as _mnemo.author on each new record (as Mnemo::set_author), kept across reloads. Writes nothing.

Source

pub fn hold_presence(&mut self) -> Result<()>

13a (13.3): hold this handle’s author’s presence lock for the handle’s life, in the sidecar directory, so Mnemo::who sees the agent as alive and its claims may lapse early once its process is gone. Only a long-lived process should (the MCP server); a hook or a CLI call never does. It never touches the brain’s own lock. Needs an author (SharedMnemo::set_author) and a usable sidecar directory.

Source

pub fn set_embedder<E: Embedder + 'static>(&mut self, embedder: E) -> Result<()>

Attach an embedder (as Mnemo::set_embedder). It’s kept across reloads. When the file already records this embedder’s identity, this is a read window and writes nothing; otherwise the identity is recorded in a write window.

Source

pub fn rekey(&mut self, new_passphrase: &str, kdf: KdfParams) -> Result<()>

Change the passphrase (as Mnemo::rekey, in a write window), and replace the secret the handle keeps once the new one is in force, so the handle can still follow a compaction or recover the file afterwards. An error leaves the old secret in force and kept, unless it says the file may open with either.

Source

pub fn rekey_with_key(&mut self, new_key: &[u8; 32]) -> Result<()>

SharedMnemo::rekey to a raw 256-bit key (as Mnemo::rekey_with_key).

Source

pub fn rekey_cleanup_error(&self) -> Option<&str>

After a successful SharedMnemo::rekey, what couldn’t be scrubbed of the old key wrap (see Mnemo::rekey_cleanup_error).

Source

pub fn set_cancel(&mut self, token: Option<CancelToken>)

Give the handle a new cancel token for its later calls, or none (RB-007.1). A cancelled token stays cancelled, so after a cancel the handle needs a new one (or None) to wait for a lock again. A cancel reaches only a call that is waiting for a lock.

Source

pub fn embedder_arc(&self) -> Option<Arc<dyn Embedder>>

The embedder attached to the handle, if any (shared, so a binding can embed outside a window and then call SharedMnemo::write).

Source

pub fn notices(&self) -> &[String]

The warnings to show once: a sidecar directory that can’t be used, a synced folder, an allowed network filesystem.

Source

pub fn options(&self) -> &SharedOptions

The handle’s options: those it was opened with, and the cancel token SharedMnemo::set_cancel gave it last.

Source

pub fn close(self) -> Result<()>

Close the handle. It holds no lock between calls, so this only drops what it kept: the secret (zeroized) and the access statistics no write has applied yet.

Trait Implementations§

Source§

impl Debug for SharedMnemo

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V