Struct 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§

Source§

impl SearchPath

Source

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.

Source

pub fn path() -> Result<Self, Box<dyn Error>>

Construct a new search path by parsing the environment variable named PATH.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn find_file(&self, file_name: &Path) -> Option<PathBuf>

Return the first file found in the search path, or None.

Source

pub fn find_directory(&self, file_name: &Path) -> Option<PathBuf>

Return the first directory found in the search path, or None.

Source

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.

Source

pub fn is_empty(&self) -> bool

Return true if this instance has no paths to search, else false.

Source

pub fn len(&self) -> usize

Return the current number of paths in the list of paths to search.

Source

pub fn contains(&self, path: &PathBuf) -> bool

Return true if the list of paths to search contains the path value, else false.

Source

pub fn contains_cwd(&self) -> bool

Return true if the list of paths to search contains the current directory path, ".", value, else false.

Source

pub fn iter(&self) -> impl Iterator<Item = &PathBuf>

Return an iterator over all the paths in the list of paths to search.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn remove(&mut self, path: &PathBuf)

Remove the path from the list of paths to search, this has no effect if the path was not in the list.

Source

pub fn dedup(&mut self)

Ensure that only one copy of a path exists in the list of paths to search. This operation will ensure the ordering of paths remains the same and keep the first duplicate it finds and remove any subsequent ones.

Trait Implementations§

Source§

impl Clone for SearchPath

Source§

fn clone(&self) -> SearchPath

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SearchPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SearchPath

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for SearchPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for SearchPath

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<PathBuf> for SearchPath

Source§

fn from(v: PathBuf) -> Self

Converts to this type from the input type.
Source§

impl From<SearchPath> for Vec<PathBuf>

Source§

fn from(p: SearchPath) -> Self

Converts to this type from the input type.
Source§

impl From<String> for SearchPath

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<&Path>> for SearchPath

Source§

fn from(vs: Vec<&Path>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<&str>> for SearchPath

Source§

fn from(vs: Vec<&str>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<PathBuf>> for SearchPath

Source§

fn from(vs: Vec<PathBuf>) -> Self

Converts to this type from the input type.
Source§

impl IntoIterator for SearchPath

Source§

type Item = PathBuf

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<PathBuf>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for SearchPath

Source§

fn eq(&self, other: &SearchPath) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SearchPath

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.