Struct search_path::SearchPath
source · [−]pub struct SearchPath { /* private fields */ }
Expand description
This is the search path itself, it wraps a list of file paths which can then be used to find file system entries. See the module description for an overview.
Implementations
sourceimpl SearchPath
impl SearchPath
sourcepub fn new(env_var: &str) -> Result<Self, Box<dyn Error>>
pub fn new(env_var: &str) -> Result<Self, Box<dyn Error>>
Construct a new search path by parsing the environment variable named env_var
into
separate paths. Paths are separated by the ';'
character on Windows, and the ':'
character on other platforms.
If the environment variable is not present, or could not be read this function returns an error.
use search_path::SearchPath;
let search_path = SearchPath::new("CMD_PATH").expect("No $CMD_PATH present");
Constructors do not check for duplicate paths, to remove duplicates see the
dedup
) method.
sourcepub fn path() -> Result<Self, Box<dyn Error>>
pub fn path() -> Result<Self, Box<dyn Error>>
Construct a new search path by parsing the environment variable named PATH
.
sourcepub fn new_or<T: Into<SearchPath>>(env_var: &str, default: T) -> Self
pub fn new_or<T: Into<SearchPath>>(env_var: &str, default: T) -> Self
Construct a new search path by parsing the environment variable named env_var
into
separate paths. Paths are separated by the ';'
character on Windows, and the ':'
character on other platforms.
If the environment variable is not present, or could not be read this function returns
the default value provided instead. The default value may be any value that has an
Into
implementation for SearchPath
.
use search_path::SearchPath;
let search_path = SearchPath::new_or("CMD_PATH", ".");
Constructors do not check for duplicate paths, to remove duplicates see the
dedup
) method.
sourcepub fn new_or_default(env_var: &str) -> Self
pub fn new_or_default(env_var: &str) -> Self
Construct a new search path by parsing the environment variable named env_var
into
separate paths. Paths are separated by the ';'
character on Windows, and the ':'
character on other platforms.
If the environment variable is not present, or could not be read this function returns
the value of Default::default()
implemented for SearchPath
instead.
use search_path::SearchPath;
let search_path = SearchPath::new_or_default("CMD_PATH");
Constructors do not check for duplicate paths, to remove duplicates see the
dedup
) method.
sourcepub fn find(&self, file_name: &Path) -> Option<PathBuf>
pub fn find(&self, file_name: &Path) -> Option<PathBuf>
Return the first file system entity, either file or directory, found in the search path, or
None
.
sourcepub fn find_all(&self, file_name: &Path) -> Vec<PathBuf>
pub fn find_all(&self, file_name: &Path) -> Vec<PathBuf>
Return all the file system entities, either file or directory, found in the search path.
sourcepub fn find_file(&self, file_name: &Path) -> Option<PathBuf>
pub fn find_file(&self, file_name: &Path) -> Option<PathBuf>
Return the first file found in the search path, or None
.
sourcepub fn find_directory(&self, file_name: &Path) -> Option<PathBuf>
pub fn find_directory(&self, file_name: &Path) -> Option<PathBuf>
Return the first directory found in the search path, or None
.
sourcepub fn find_if_name_only(&self, file_name: &Path) -> Option<PathBuf>
pub fn find_if_name_only(&self, file_name: &Path) -> Option<PathBuf>
Return the first file found in the search path, or None
. This method will only
consider file_name
if it is not a path, if it has any path components the method
will also return None
.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true
if this instance has no paths to search, else false
.
sourcepub fn contains(&self, path: &PathBuf) -> bool
pub fn contains(&self, path: &PathBuf) -> bool
Return true
if the list of paths to search contains the path
value, else false
.
sourcepub fn contains_cwd(&self) -> bool
pub fn contains_cwd(&self) -> bool
Return true
if the list of paths to search contains the current directory path, "."
,
value, else false
.
sourcepub fn iter(&self) -> impl Iterator<Item = &PathBuf>
pub fn iter(&self) -> impl Iterator<Item = &PathBuf>
Return an iterator over all the paths in the list of paths to search.
sourcepub fn append(&mut self, path: PathBuf)
pub fn append(&mut self, path: PathBuf)
Append the provided path
to the list of paths to search.
This operation does not check for duplicate paths, to remove duplicates see the
dedup
) method.
sourcepub fn append_cwd(&mut self)
pub fn append_cwd(&mut self)
Append the current directory path, "."
, to the list of paths to search.
This operation does not check for duplicate paths, to remove duplicates see the
dedup
) method.
sourcepub fn prepend(&mut self, path: PathBuf)
pub fn prepend(&mut self, path: PathBuf)
Prepend the provided path
to the list of paths to search.
This operation does not check for duplicate paths, to remove duplicates see the
dedup
) method.
sourcepub fn prepend_cwd(&mut self)
pub fn prepend_cwd(&mut self)
Prepend the current directory path, "."
, to the list of paths to search.
This operation does not check for duplicate paths, to remove duplicates see the
dedup
) method.
Trait Implementations
sourceimpl Clone for SearchPath
impl Clone for SearchPath
sourcefn clone(&self) -> SearchPath
fn clone(&self) -> SearchPath
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more