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
impl MemoryTree
Sourcepub fn create_new(
&mut self,
path: &RelPath,
text: String,
) -> Result<(), TreeError>
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.
Sourcepub fn replace(&mut self, path: &RelPath, text: String) -> Result<(), TreeError>
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.
Sourcepub fn try_from_iter<I, K, V>(entries: I) -> Result<Self, TreeError>
pub fn try_from_iter<I, K, V>(entries: I) -> Result<Self, TreeError>
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
impl Clone for MemoryTree
Source§impl Debug for MemoryTree
impl Debug for MemoryTree
Source§impl Default for MemoryTree
impl Default for MemoryTree
impl Eq for MemoryTree
Source§impl<K: AsRef<str>, V: Into<String>> FromIterator<(K, V)> for MemoryTree
impl<K: AsRef<str>, V: Into<String>> FromIterator<(K, V)> for MemoryTree
impl ParallelTree for MemoryTree
Source§impl PartialEq for MemoryTree
impl PartialEq for MemoryTree
impl StructuralPartialEq for MemoryTree
Source§impl Tree for MemoryTree
impl Tree for MemoryTree
Source§fn read_bytes(
&self,
path: &RelPath,
max_bytes: u64,
) -> Result<Vec<u8>, TreeError>
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>
fn read(&self, path: &RelPath, max_bytes: u64) -> Result<String, TreeError>
path. Read moreSource§fn read_unseen(
&self,
path: &RelPath,
max_bytes: u64,
seen: &dyn Fn(&FileId) -> bool,
) -> Result<Opened, TreeError>
fn read_unseen( &self, path: &RelPath, max_bytes: u64, seen: &dyn Fn(&FileId) -> bool, ) -> Result<Opened, TreeError>
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 moreSource§fn list(&self, path: &RelPath) -> Result<Vec<Entry>, TreeError>
fn list(&self, path: &RelPath) -> Result<Vec<Entry>, TreeError>
path, sorted by name. Read moreAuto Trait Implementations§
impl Forget for MemoryTree
impl Freeze for MemoryTree
impl Move for MemoryTree
impl RefUnwindSafe for MemoryTree
impl Send for MemoryTree
impl Sync for MemoryTree
impl Unpin for MemoryTree
impl UnsafeUnpin for MemoryTree
impl UnwindSafe for MemoryTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> EvidenceLease for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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