Struct simpath::Simpath [] [src]

pub struct Simpath { /* fields omitted */ }

Methods

impl Simpath
[src]

[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(path) => println!("'ls' was found at '{}'", path.display()),
        Err(e)   => println!("{}", e)
    }
}

[src]

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

[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());
}

[src]

Try to find a file by filename (not full path) on a search path. Searching for a file could cause errors, so Result is returned If it is found Ok(PathBuf) path to the file will be returned. 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())
    }
}

[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());
}

[src]

Check if a search path contains a directory

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!");
    }
}

[src]

Add entries to the search path, by reading from an environment variable. The variable should have a set of ':' separated directory names. To be added each direcory should 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());
    }
}

Trait Implementations

impl Clone for Simpath
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Simpath
[src]

[src]

Formats the value using the given formatter.

impl Display for Simpath
[src]

[src]

Formats the value using the given formatter. Read more