Struct simpath::Simpath[][src]

pub struct Simpath { /* fields omitted */ }

Simpath is the struct returned when you create a new on using a named environment variable which you then use to interact with the Simpath

Implementations

impl Simpath[src]

pub fn new(var_name: &str) -> Self[src]

Create a new simpath, providing the name of the environment variable to initialize the search path with. If an environment variable of that name exists and it will be parsed as a ‘:’ separated list of paths to search. Only paths detected as directories will be used, not files.

If an environment variable of that name is not found, a new simpath will be created anyway and it can have directories added to it programatically and used in the normal fashion to search for files

extern crate simpath;
use simpath::Simpath;

fn main() {
    let search_path = Simpath::new("PATH");
    let ls_file = search_path.find("ls");
    match ls_file {
        Ok(found) => println!("'ls' was found at '{:?}'", found),
        Err(e)   => println!("{}", e)
    }
}

pub fn new_with_separator(var_name: &str, separator: char) -> Self[src]

Create a new simpath, providing the name of the environment variable to initialize the search path with and the separator character for this search path to be used from here on. If an environment variable of that name exists and it will be parsed as a list of paths to search. Only paths detected as directories will be used, not files.

If an environment variable of that name is not found, a new simpath will be created anyway and it can have directories added to it programatically and used in the normal fashion to search for files.

In all cases, the separator char for this search path will be set to separator from here on.

extern crate simpath;
use simpath::Simpath;
use std::env;

fn main() {
    env::set_var("TEST", "/,.,~");
    let search_path = Simpath::new("TEST");
    let two = search_path.find(".");
    match two {
        Ok(found) => println!("'.' was found at '{:?}'", found),
        Err(e)   => println!("{}", e)
    }
}

pub fn separator(&self) -> char[src]

Get the currently set separator character that is used when parsing entries from an environment variable

pub fn name(&self) -> &str[src]

Get the name associated with the simpath. Note that this could be an empty String

extern crate simpath;
use simpath::Simpath;

fn main() {
    let search_path = Simpath::new("PATH");
    println!("Directories in Search Path: {:?}", search_path.name());
}

pub fn directories(&self) -> &HashSet<PathBuf>[src]

Get the list of directories that are included in the Search Path

extern crate simpath;
use simpath::Simpath;

fn main() {
    let search_path = Simpath::new("PATH");
    println!("Directories in Search Path: {:?}", search_path.directories());
}

pub fn find(&self, file_name: &str) -> Result<FoundType, Error>[src]

Try to find a file or resource by name (not full path) on a search path. Searching for a file could cause errors, so Result<FoundType, io::Error> is returned If it is found Ok(FoundType) is returned indicating where the resource/file can be found. If it is not found then Err is returned.

extern crate simpath;
use simpath::Simpath;

fn main() {
    let search_path = Simpath::new("PATH");
    match search_path.find("my-file") {
        Ok(_found_dir) => println!("Didn't expect that!!"),
        Err(e)         => println!("{}", e.to_string())
    }
}

pub fn find_type(
    &self,
    file_name: &str,
    file_type: FileType
) -> Result<FoundType, Error>
[src]

find an entry of a specific FileType in a Path

extern crate simpath;
use simpath::Simpath;

fn main() {
    use simpath::FileType;
    let search_path = Simpath::new("PATH");
    match search_path.find_type("my-file", FileType::Directory) {
        Ok(_found_dir) => println!("Didn't expect that!!"),
        Err(e)         => println!("{}", e.to_string())
    }
}

pub fn add(&mut self, entry: &str)[src]

Add an to the search path.

if “urls” feature is enabled: If it parses as as web Url it will be added to the list of base Urls to search, otherwise it will be added to the list of directories to search. if “urls” feature is not enabled: It is assumed to be a directory and added using add_directory()

extern crate simpath;
use simpath::Simpath;

fn main() {
    let mut search_path = Simpath::new("PATH");
    search_path.add(".");

#[cfg(feature = "urls")]
    search_path.add("http://ibm.com");

    println!("{}", search_path);
}

pub fn add_directory(&mut self, dir: &str)[src]

Add a directory to the list of directories to search for files. If the directory passed does not exist, or is not a directory, or cannot be read then it will be ignored.

extern crate simpath;
use simpath::Simpath;

fn main() {
    let mut search_path = Simpath::new("PATH");
    search_path.add_directory(".");
    println!("Directories in Search Path: {:?}", search_path.directories());
}

pub fn contains(&self, entry: &str) -> bool[src]

Check if a search path contains an entry

extern crate simpath;
use simpath::Simpath;

fn main() {
    let mut search_path = Simpath::new("FakeEnvVar");
    if search_path.contains(".") {
        println!("Well that's a surprise!");
    }
}

pub fn add_from_env_var(&mut self, var_name: &str)[src]

Add entries to the search path, by reading them from an environment variable.

The environment variable should have a set of entries separated by the separator character. By default the separator char is ":" (on non-windows platforms) and ";" (on windows) but it can be modified after creation of search path.

The environment variable is parsed using the separator char set at the time this function is called.

To be added each entry must exist and be readable.

extern crate simpath;
use simpath::Simpath;

fn main() {
    let mut search_path = Simpath::new("MyPathName");
    search_path.add_from_env_var("PATH");
    if search_path.contains(".") {
        println!("'.' was in your 'PATH' and has been added to the search path called '{}'",
                 search_path.name());
    }
}

pub fn add_from_env_var_with_separator(
    &mut self,
    var_name: &str,
    separator: char
)
[src]

Add entries to the search path, by reading them from an environment variable.

The environment variable should have a set of entries separated by the specified separator character.

To be added each entry must exist and be readable.

NOTE: The separator char is only used while parsing the specified environment variable and does not modify the separator character in use in the Simpath after this function completes.

extern crate simpath;
use simpath::Simpath;
use std::env;

fn main() {
    let mut search_path = Simpath::new("MyPathName");
    env::set_var("TEST", "/,.,~");
    search_path.add_from_env_var_with_separator("TEST", ',');
    if search_path.contains(".") {
        println!("'.' was in your 'TEST' environment variable and has been added to the search path called '{}'",
                 search_path.name());
    }
}

Trait Implementations

impl Clone for Simpath[src]

impl Debug for Simpath[src]

impl Display for Simpath[src]

Auto Trait Implementations

impl RefUnwindSafe for Simpath

impl Send for Simpath

impl Sync for Simpath

impl Unpin for Simpath

impl UnwindSafe for Simpath

Blanket Implementations

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.