pub struct KeyedFileTree<T>{ /* private fields */ }
Expand description
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);
Implementations§
Source§impl<T> KeyedFileTree<T>
impl<T> KeyedFileTree<T>
Sourcepub fn new(persistent: bool) -> Result<KeyedFileTree<T>>
pub fn new(persistent: bool) -> Result<KeyedFileTree<T>>
Create a new instance. If persistence
is false
, the backing
directory structure will be removed when the returned instance is
dropped.
Sourcepub fn new_in(path: PathBuf, persistent: bool) -> Result<KeyedFileTree<T>>
pub fn new_in(path: PathBuf, persistent: bool) -> Result<KeyedFileTree<T>>
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.
Sourcepub fn from_existing(
path: PathBuf,
existing_files: HashMap<T, PathBuf>,
) -> KeyedFileTree<T>
pub fn from_existing( 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()
.
Sourcepub fn get(&mut self, key: T) -> Result<PathBuf>
pub fn get(&mut self, key: T) -> Result<PathBuf>
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.
Sourcepub fn get_existing_files(self) -> HashMap<T, PathBuf>
pub fn get_existing_files(self) -> HashMap<T, PathBuf>
Gets the map of keys to PathBuf
s. Useful for re-creating an instance
later with from_existing()
.