[−][src]Struct simpath::Simpath
Methods
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(path) => println!("'ls' was found at '{}'", path.display()), Err(e) => println!("{}", e) } }
pub fn name(&self) -> &str[src]
Get the name associated with the simpath. Note that this could be an empty String
pub 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()); }
pub 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 Result<PathBuf, io::Error> 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()) } }
pub fn find_type(
&self,
file_name: &str,
file_type: FileType
) -> Result<PathBuf, Error>[src]
&self,
file_name: &str,
file_type: FileType
) -> Result<PathBuf, Error>
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, 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!"); } }
pub 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]
default fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Display for Simpath[src]
impl Debug for Simpath[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> From for T[src]
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,