Skip to main content

MemoryTree

Struct MemoryTree 

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

A tree of files held in memory: a map of path to text.

Directories are inferred from the keys. There are no symlinks and no special files. A key is normalised like a RelPath, and a .. segment is applied to the keys’ own directories.

MemoryTree::try_from_iter refuses a bad key with a TreeError. The infallible From and FromIterator conversions cannot return one, so a tree built from a bad key reports that same error from every call and never serves a partial tree.

Implementations§

Source§

impl MemoryTree

Source

pub fn create_new( &mut self, path: &RelPath, text: String, ) -> Result<(), TreeError>

Create a file exclusively, inferring its directories as for construction.

§Errors

Returns the tree’s original construction fault, WrongAuthority for a foreign path, DuplicatePath for an existing file, or NotRegular for a directory destination or a file used as an ancestor. Refusal changes nothing. File identities remain the normalised keys.

Source

pub fn replace(&mut self, path: &RelPath, text: String) -> Result<(), TreeError>

Replace an existing regular file as one change, preserving its identity.

§Errors

As MemoryTree::create_new, except a missing file is NotFound and an existing file is required. Refusal preserves the entire tree.

Source

pub fn try_from_iter<I, K, V>(entries: I) -> Result<Self, TreeError>
where I: IntoIterator<Item = (K, V)>, K: AsRef<str>, V: Into<String>,

Build a tree from (path, text) pairs.

§Errors

Returns TreeError::OutsideRoot naming a key that is absolute or climbs above the root, and TreeError::NotRegular naming a key that is a file and also holds other keys below it, and TreeError::DuplicatePath naming a key whose normalised path an earlier key already holds.

Trait Implementations§

Source§

impl Clone for MemoryTree

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryTree

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for MemoryTree

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for MemoryTree

Source§

impl<const N: usize> From<[(&str, &str); N]> for MemoryTree

Source§

fn from(entries: [(&str, &str); N]) -> Self

Converts to this type from the input type.
Source§

impl<K: AsRef<str>, V: Into<String>> FromIterator<(K, V)> for MemoryTree

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(entries: I) -> Self

Creates a value from an iterator. Read more
Source§

impl ParallelTree for MemoryTree

Source§

impl PartialEq for MemoryTree

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MemoryTree

Source§

impl Tree for MemoryTree

Source§

fn read_bytes( &self, path: &RelPath, max_bytes: u64, ) -> Result<Vec<u8>, TreeError>

The memory tree holds text, so its bytes are the UTF-8 of that text.

Source§

fn read(&self, path: &RelPath, max_bytes: u64) -> Result<String, TreeError>

The text of the file at path. Read more
Source§

fn read_unseen( &self, path: &RelPath, max_bytes: u64, seen: &dyn Fn(&FileId) -> bool, ) -> Result<Opened, TreeError>

Open the file at path once, take its identity from that open, and read its text from the same open unless seen says the identity is one the caller already holds. Read more
Source§

fn list(&self, path: &RelPath) -> Result<Vec<Entry>, TreeError>

The entries of the directory at path, sorted by name. Read more
Source§

fn entry(&self, path: &RelPath) -> Result<Option<EntryKind>, TreeError>

What is at path, or None when nothing is. Read more
Source§

fn identity(&self, path: &RelPath) -> Result<FileId, TreeError>

The identity of the file at path, without reading it: the identity Tree::read_unseen gives when every identity counts as seen. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Whether this borrowed key equals the stored key.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> EvidenceLease for T
where T: Debug + Send + Sync,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.