[][src]Struct file_tree::KeyedFileTree

pub struct KeyedFileTree<T> where
    T: Hash + Eq
{ /* fields omitted */ }

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]

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]

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 PathBufs. Useful for re-creating an instance later with from_existing().

Auto Trait Implementations

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

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

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

impl<T> UnwindSafe for KeyedFileTree<T> where
    T: RefUnwindSafe + UnwindSafe

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

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]