Skip to main content

M2dirClient

Struct M2dirClient 

Source
pub struct M2dirClient { /* private fields */ }
Available on crate feature 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

Source

pub fn new(root: impl Into<M2dirPath>) -> Self

Builds a client rooted at root. No filesystem check is performed at construction time.

Source

pub fn root(&self) -> &M2dirPath

Returns the filesystem root this client operates on.

Source

pub fn run<C, T, E>(&self, coroutine: C) -> Result<T, M2dirClientError>
where C: M2dirCoroutine<Yield = M2dirYield, Return = Result<T, E>>, M2dirClientError: From<E>,

Drives any standard-shape coroutine (Yield = M2dirYield, Return = Result<Output, Error>) against the local filesystem until it terminates.

Source

pub fn open_store(&self) -> Result<M2dirStore, M2dirClientError>

Opens the m2store at the client root, returning a typed handle on success.

Source

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.

Source

pub fn open_m2dir( &self, path: impl Into<M2dirPath>, ) -> Result<M2dir, M2dirClientError>

Opens an existing m2dir at path, validating the .m2dir marker.

Source

pub fn create_m2dir(&self, name: &str) -> Result<M2dir, M2dirClientError>

Creates the m2dir folder name and writes the .m2dir marker.

Source

pub fn delete_m2dir( &self, path: impl Into<M2dirPath>, ) -> Result<(), M2dirClientError>

Recursively removes the m2dir at path.

Source

pub fn list_m2dirs(&self) -> Result<BTreeSet<M2dir>, M2dirClientError>

Lists every m2dir under the store root.

Source

pub fn list_entries( &self, m2dir: M2dir, ) -> Result<Vec<M2dirEntry>, M2dirClientError>

Lists every entry inside m2dir.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn delete_entry( &self, m2dir: M2dir, id: impl ToString, ) -> Result<(), M2dirClientError>

Removes entry id and every matching .meta/<id>* file.

Source

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.

Source

pub fn add_flags( &self, m2dir: &M2dir, id: impl AsRef<str>, flags: M2dirFlags, ) -> Result<(), M2dirClientError>

Adds flags to entry id’s flags metadata file.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for M2dirClient

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<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.