Struct simpath::Simpath
[−]
[src]
pub struct Simpath { /* fields omitted */ }
Methods
impl Simpath
[src]
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(path) => println!("'ls' was found at '{}'", path.display()), Err(e) => println!("{}", e) } }
fn name(&self) -> &str
[src]
Get the name associated with the simpath. Note that this could be an empty String
fn directories(&self) -> &Vec<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()); }
fn find(&self, file_name: &str) -> Result<PathBuf, Error>
[src]
Try to find a file by filename (not full path) on a search path.
Searching for a file could cause errors, so ResultOk(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()) } }
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()); }
fn contains(&self, dir: &str) -> bool
[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!"); } }
fn add_from_env_var(&mut self, var_name: &str)
[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]
fn clone(&self) -> Simpath
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more