Skip to main content

MemoryStore

Struct MemoryStore 

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

An in-memory tree store that implements the StructFS store conventions:

  • Reading a prefix returns its subtree as a Value::Map of children.
  • Writing deep paths creates intermediate maps as needed.
  • Writing Value::Null deletes the node and its entire subtree (component-wise: deleting accounts does not touch accounts_other).
  • Writing a Value::Map at a parent replaces the full state under that path — stale descendants do not survive.

This is the reference implementation certified by the conformance suite; use that suite to verify other stores implement the same semantics.

§Example

use structfs_core_store::{MemoryStore, Reader, Writer, Record, Value, path};

let mut store = MemoryStore::new();
store.write(&path!("users/alice/name"), Record::parsed(Value::from("Alice"))).unwrap();

// Reading the prefix returns the subtree
let users = store.read(&path!("users")).unwrap().unwrap();
assert!(users.as_value().unwrap().is_map());

// Null deletes the subtree
store.write(&path!("users"), Record::parsed(Value::Null)).unwrap();
assert!(store.read(&path!("users/alice/name")).unwrap().is_none());

Implementations§

Source§

impl MemoryStore

Source

pub fn new() -> Self

Create a new empty store.

Source

pub fn with_root(root: Value) -> Self

Create a store with initial contents.

Source

pub fn root(&self) -> &Value

Borrow the root value.

Trait Implementations§

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 Reader for MemoryStore

Source§

fn read(&mut self, from: &Path) -> Result<Option<Record>, Error>

Read a record from a path. Read more
Source§

fn read_children(&mut self, from: &Path) -> Result<Option<Vec<String>>, Error>

Enumerate the child names directly under a path. Read more
Source§

impl Writer for MemoryStore

Source§

fn write(&mut self, to: &Path, data: Record) -> Result<Path, Error>

Write a record to a path. 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> Store for T
where T: Reader + Writer,

Source§

impl<T> Store for T
where T: Reader + Writer,

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.