pub struct M2dirClient { /* private fields */ }client only.Expand description
Std-blocking m2dir client wrapping a filesystem root.
The root must point to an m2store: a directory containing a
.m2store marker. M2dir helpers resolve folder names against
this root.
Implementations§
Source§impl M2dirClient
impl M2dirClient
Sourcepub fn new(root: impl Into<M2dirPath>) -> Self
pub fn new(root: impl Into<M2dirPath>) -> Self
Builds a client rooted at root. No filesystem check is
performed at construction time.
Sourcepub fn run<C, T, E>(&self, coroutine: C) -> Result<T, M2dirClientError>
pub fn run<C, T, E>(&self, coroutine: C) -> Result<T, M2dirClientError>
Drives any standard-shape coroutine (Yield = M2dirYield,
Return = Result<Output, Error>) against the local
filesystem until it terminates.
Sourcepub fn open_store(&self) -> Result<M2dirStore, M2dirClientError>
pub fn open_store(&self) -> Result<M2dirStore, M2dirClientError>
Opens the m2store at the client root, returning a typed handle on success.
Sourcepub fn init_store(&self) -> Result<M2dirStore, M2dirClientError>
pub fn init_store(&self) -> Result<M2dirStore, M2dirClientError>
Initialises a brand new m2store at the client root: creates
the directory if needed and writes the .m2store marker.
Sourcepub fn open_m2dir(
&self,
path: impl Into<M2dirPath>,
) -> Result<M2dir, M2dirClientError>
pub fn open_m2dir( &self, path: impl Into<M2dirPath>, ) -> Result<M2dir, M2dirClientError>
Opens an existing m2dir at path, validating the .m2dir
marker.
Sourcepub fn create_m2dir(&self, name: &str) -> Result<M2dir, M2dirClientError>
pub fn create_m2dir(&self, name: &str) -> Result<M2dir, M2dirClientError>
Creates the m2dir folder name and writes the .m2dir
marker.
Sourcepub fn delete_m2dir(
&self,
path: impl Into<M2dirPath>,
) -> Result<(), M2dirClientError>
pub fn delete_m2dir( &self, path: impl Into<M2dirPath>, ) -> Result<(), M2dirClientError>
Recursively removes the m2dir at path.
Sourcepub fn list_m2dirs(&self) -> Result<BTreeSet<M2dir>, M2dirClientError>
pub fn list_m2dirs(&self) -> Result<BTreeSet<M2dir>, M2dirClientError>
Lists every m2dir under the store root.
Sourcepub fn list_entries(
&self,
m2dir: M2dir,
) -> Result<Vec<M2dirEntry>, M2dirClientError>
pub fn list_entries( &self, m2dir: M2dir, ) -> Result<Vec<M2dirEntry>, M2dirClientError>
Lists every entry inside m2dir.
Sourcepub fn read_entry(
&self,
entry: &M2dirEntry,
) -> Result<Vec<u8>, M2dirClientError>
pub fn read_entry( &self, entry: &M2dirEntry, ) -> Result<Vec<u8>, M2dirClientError>
Reads the file backing entry and validates its checksum.
Prefer this over Self::get when the entry is already known:
skips the directory scan used to resolve an id.
Sourcepub fn read_entries(
&self,
m2dir: &M2dir,
entries: &[M2dirEntry],
) -> Result<BTreeSet<M2dirFullEntry>, M2dirClientError>
pub fn read_entries( &self, m2dir: &M2dir, entries: &[M2dirEntry], ) -> Result<BTreeSet<M2dirFullEntry>, M2dirClientError>
Reads the bytes and flags of every entry sequentially.
Returns an unordered set: callers that need a specific order
must sort the collected entries themselves. Use
Self::read_entries_par for the parallel variant.
Sourcepub fn read_entries_par(
&self,
m2dir: &M2dir,
entries: &[M2dirEntry],
) -> Result<BTreeSet<M2dirFullEntry>, M2dirClientError>
pub fn read_entries_par( &self, m2dir: &M2dir, entries: &[M2dirEntry], ) -> Result<BTreeSet<M2dirFullEntry>, M2dirClientError>
Parallel variant of Self::read_entries backed by a
std::thread::scope worker pool sized to
thread::available_parallelism.
Sourcepub fn get(
&self,
m2dir: M2dir,
id: impl ToString,
) -> Result<(M2dirEntry, Vec<u8>), M2dirClientError>
pub fn get( &self, m2dir: M2dir, id: impl ToString, ) -> Result<(M2dirEntry, Vec<u8>), M2dirClientError>
Locates and reads entry id from m2dir, validating the
checksum embedded in the filename.
Sourcepub fn store(
&self,
m2dir: M2dir,
bytes: Vec<u8>,
) -> Result<M2dirEntry, M2dirClientError>
pub fn store( &self, m2dir: M2dir, bytes: Vec<u8>, ) -> Result<M2dirEntry, M2dirClientError>
Writes bytes to a temporary file inside m2dir, then
atomically renames it to its checksum-based final filename.
Sourcepub fn delete_entry(
&self,
m2dir: M2dir,
id: impl ToString,
) -> Result<(), M2dirClientError>
pub fn delete_entry( &self, m2dir: M2dir, id: impl ToString, ) -> Result<(), M2dirClientError>
Removes entry id and every matching .meta/<id>* file.
Sourcepub fn read_flags(
&self,
m2dir: &M2dir,
id: impl AsRef<str>,
) -> Result<M2dirFlags, M2dirClientError>
pub fn read_flags( &self, m2dir: &M2dir, id: impl AsRef<str>, ) -> Result<M2dirFlags, M2dirClientError>
Reads the .flags metadata file for entry id inside
m2dir, returning an empty set if the file is missing.
Sourcepub fn add_flags(
&self,
m2dir: &M2dir,
id: impl AsRef<str>,
flags: M2dirFlags,
) -> Result<(), M2dirClientError>
pub fn add_flags( &self, m2dir: &M2dir, id: impl AsRef<str>, flags: M2dirFlags, ) -> Result<(), M2dirClientError>
Adds flags to entry id’s flags metadata file.
Sourcepub fn remove_flags(
&self,
m2dir: &M2dir,
id: impl AsRef<str>,
flags: M2dirFlags,
) -> Result<(), M2dirClientError>
pub fn remove_flags( &self, m2dir: &M2dir, id: impl AsRef<str>, flags: M2dirFlags, ) -> Result<(), M2dirClientError>
Removes flags from entry id’s flags metadata file. When
the resulting set is empty the file is deleted.
Sourcepub fn set_flags(
&self,
m2dir: &M2dir,
id: impl AsRef<str>,
flags: M2dirFlags,
) -> Result<(), M2dirClientError>
pub fn set_flags( &self, m2dir: &M2dir, id: impl AsRef<str>, flags: M2dirFlags, ) -> Result<(), M2dirClientError>
Replaces entry id’s flags metadata file with flags,
deleting it when flags is empty.