Struct KeyedFileTree

Source
pub struct KeyedFileTree<T>
where T: Hash + Eq,
{ /* 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>
where T: Hash + Eq,

Source

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.

Examples found in repository?
examples/keyed_file_tree.rs (line 4)
3fn main() {
4    let mut file_tree = KeyedFileTree::new(false).unwrap();
5
6    let writeable_path_1 = file_tree.get(String::from("key1")).unwrap();
7    let writeable_path_2 = file_tree.get(String::from("key2")).unwrap();
8
9    assert_ne!(writeable_path_1, writeable_path_2);
10}
Source

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.

Source

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

Source

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.

Examples found in repository?
examples/keyed_file_tree.rs (line 6)
3fn main() {
4    let mut file_tree = KeyedFileTree::new(false).unwrap();
5
6    let writeable_path_1 = file_tree.get(String::from("key1")).unwrap();
7    let writeable_path_2 = file_tree.get(String::from("key2")).unwrap();
8
9    assert_ne!(writeable_path_1, writeable_path_2);
10}
Source

pub fn get_root(&self) -> PathBuf

Return the root path for the file tree.

Source

pub fn get_existing_files(self) -> HashMap<T, PathBuf>

Gets the map of keys to PathBufs. Useful for re-creating an instance later with from_existing().

Auto Trait Implementations§

§

impl<T> Freeze for KeyedFileTree<T>

§

impl<T> RefUnwindSafe for KeyedFileTree<T>
where T: RefUnwindSafe,

§

impl<T> Send for KeyedFileTree<T>
where T: Send,

§

impl<T> Sync for KeyedFileTree<T>
where T: Sync,

§

impl<T> Unpin for KeyedFileTree<T>
where T: Unpin,

§

impl<T> UnwindSafe for KeyedFileTree<T>
where T: UnwindSafe,

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.