Struct WhichConfig

Source
pub struct WhichConfig<TSys: Sys, F = Noop> { /* private fields */ }
Expand description

A wrapper containing all functionality in this crate.

Implementations§

Source§

impl WhichConfig<&RealSys, Noop>

Source

pub fn new() -> Self

Source§

impl<TSys: Sys> WhichConfig<TSys, Noop>

Source

pub fn new_with_sys(sys: TSys) -> Self

Creates a new WhichConfig with the given sys::Sys.

This is useful for providing all the system related functionality to this crate.

Source§

impl<'a, TSys: Sys + 'a, F: NonFatalErrorHandler + 'a> WhichConfig<TSys, F>

Source

pub fn system_cwd(self, use_cwd: bool) -> Self

Whether or not to use the current working directory. true by default.

§Panics

If regex was set previously, and you’ve just passed in use_cwd: true, this will panic.

Source

pub fn custom_cwd(self, cwd: PathBuf) -> Self

Sets a custom path for resolving relative paths.

§Panics

If regex was set previously, this will panic.

Source

pub fn regex(self, regex: ()) -> Self

Sets the path name regex to search for. You MUST call this, or Self::binary_name prior to searching.

When Regex is disabled this function takes the unit type as a stand in. The parameter will change when Regex is enabled.

§Panics

If the regex feature wasn’t turned on for this crate this will always panic. Additionally if a cwd (aka current working directory) or binary_name was set previously, this will panic, as those options are incompatible with regex.

Source

pub fn binary_name(self, name: OsString) -> Self

Sets the path name to search for. You MUST call this, or Self::regex prior to searching.

§Panics

If a regex was set previously this will panic as this is not compatible with regex.

Source

pub fn custom_path_list(self, custom_path_list: OsString) -> Self

Uses the given string instead of the PATH env variable.

Source

pub fn system_path_list(self) -> Self

Uses the PATH env variable. Enabled by default.

Source

pub fn nonfatal_error_handler<NewF>( self, handler: NewF, ) -> WhichConfig<TSys, NewF>

Sets a closure that will receive non-fatal errors. You can also pass in other types that implement NonFatalErrorHandler.

§Example
let mut nonfatal_errors = Vec::new();

WhichConfig::new()
    .binary_name("tar".into())
    .nonfatal_error_handler(|e| nonfatal_errors.push(e))
    .all_results()
    .unwrap()
    .collect::<Vec<_>>();

if !nonfatal_errors.is_empty() {
    println!("nonfatal errors encountered: {nonfatal_errors:?}");
}

You could also log it if you choose

WhichConfig::new()
    .binary_name("tar".into())
    .nonfatal_error_handler(|e| eprintln!("{e}"))
    .all_results()
    .unwrap()
    .collect::<Vec<_>>();
Source

pub fn first_result(self) -> Result<PathBuf>

Finishes configuring, runs the query and returns the first result.

Source

pub fn all_results(self) -> Result<impl Iterator<Item = PathBuf> + 'a>

Finishes configuring, runs the query and returns all results.

Trait Implementations§

Source§

impl<F: Default> Default for WhichConfig<&RealSys, F>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<TSys, F> Freeze for WhichConfig<TSys, F>
where F: Freeze, TSys: Freeze,

§

impl<TSys, F> RefUnwindSafe for WhichConfig<TSys, F>
where F: RefUnwindSafe, TSys: RefUnwindSafe,

§

impl<TSys, F> Send for WhichConfig<TSys, F>
where F: Send, TSys: Send,

§

impl<TSys, F> Sync for WhichConfig<TSys, F>
where F: Sync, TSys: Sync,

§

impl<TSys, F> Unpin for WhichConfig<TSys, F>
where F: Unpin, TSys: Unpin,

§

impl<TSys, F> UnwindSafe for WhichConfig<TSys, F>
where F: UnwindSafe, TSys: UnwindSafe,

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> 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, 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.