[−][src]Struct file_tree::KeyedFileTree
Retrieves paths from a FileTree
using Hash
key.
File paths are stored in memory, and associated with a key. When requesting
paths from a KeyedFileTree
, an existing path will be returned if the key
has been seen before. Otherwise a new path will be created in the directory
structure and returned.
Examples
extern crate file_tree; use file_tree::KeyedFileTree; let mut file_tree = KeyedFileTree::new(false).unwrap(); let writeable_path_1 = file_tree.get(String::from("key1")).unwrap(); let writeable_path_2 = file_tree.get(String::from("key2")).unwrap(); assert_ne!(writeable_path_1, writeable_path_2);
Methods
impl<T> KeyedFileTree<T> where
T: Hash + Eq,
[src]
T: Hash + Eq,
pub fn new(persistent: bool) -> Result<KeyedFileTree<T>>
[src]
Create a new instance. If persistence
is false
, the backing
directory structure will be removed when the returned instance is
dropped.
pub fn new_in(path: PathBuf, persistent: bool) -> Result<KeyedFileTree<T>>
[src]
Create a new instance, storing the directory structure in path
. If
persistence
is false
, the backing directory structure will be
removed when the returned instance is dropped.
pub fn from_existing(
path: PathBuf,
existing_files: HashMap<T, PathBuf>
) -> KeyedFileTree<T>
[src]
path: PathBuf,
existing_files: HashMap<T, PathBuf>
) -> KeyedFileTree<T>
Creates a new instance from an existing directory structure. path
should be equivalent to the result of calling get_root()
on the
previous (persistent) KeyedFileTree
, and existing_files
should be
equivalent to calling get_existing_files()
.
pub fn get(&mut self, key: T) -> Result<PathBuf>
[src]
Reserve a spot in the directory structure for key
, and return the
associated PathBuf
. If key
has already been seen, the existing
PathBuf
will be returned.
pub fn get_root(&self) -> PathBuf
[src]
Return the root path for the file tree.
pub fn get_existing_files(self) -> HashMap<T, PathBuf>
[src]
Gets the map of keys to PathBuf
s. Useful for re-creating an instance
later with from_existing()
.
Auto Trait Implementations
impl<T> Sync for KeyedFileTree<T> where
T: Sync,
T: Sync,
impl<T> Unpin for KeyedFileTree<T> where
T: Unpin,
T: Unpin,
impl<T> Send for KeyedFileTree<T> where
T: Send,
T: Send,
impl<T> RefUnwindSafe for KeyedFileTree<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> UnwindSafe for KeyedFileTree<T> where
T: RefUnwindSafe + UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,