pub struct StandardPaths { /* private fields */ }
Expand description

Stores application and organization names and provides all the crate methods.

Implementations§

source§

impl StandardPaths

source

pub fn new<S>(app: S, org: S) -> StandardPathswhere S: Into<String>,

Constructs a new StandardPaths with the provided app and org names.

source

pub fn without_org<S>(app: S) -> StandardPathswhere S: Into<String>,

Constructs a new StandardPaths with the provided app name and with an empty organization.

source

pub fn writable_location( &self, location: LocationType ) -> Result<PathBuf, Error>

Returns the directory where files of type location should be written to.

Note: the returned path can be a directory that does not exist.

Returns Error if the location cannot be determined.

Arguments
  • location - location type.
source

pub fn standard_locations( &self, location: LocationType ) -> Result<Vec<PathBuf>, Error>

Returns all the directories of type location.

The vector of locations is sorted by priority, starting with self.writable location if it can be determined.

Returns Error if the locations cannot be determined or an empty vector if no locations for the provided type are defined.

Arguments
  • location - location type.
source

pub fn find_executable<S>(name: S) -> Option<Vec<PathBuf>>where S: Into<String>,

Returns the absolute file path to the executable with name in the system path.

It also could be used to check a path to be an executable.

Internally it calls the [self.find_executable_in_paths] method with the system path as the paths argument. On most operating systems the system path is determined by the PATH environment variable.

Note: on Windows the executable extensions from the PATHEXT environment variable are automatically appended to the name if it doesn’t contain any extension.

Returns None if no executables are found or if the provided path is not executable.

Arguments
  • name - the name of the searched executable or an absolute path which should be checked to be executable.
source

pub fn find_executable_in_paths<S, P>(name: S, paths: P) -> Option<Vec<PathBuf>>where S: Into<String>, P: AsRef<Vec<PathBuf>>,

Returns the absolute file path to the executable with name in the provided paths.

Note: on Windows the executable extensions from the PATHEXT environment variable are automatically appended to the name if it doesn’t contain any extension.

Returns None if no executables are found or if the provided path is not executable.

Arguments
  • name - the name of the searched executable or an absolute path which should be checked to be executable.
  • paths - the directories where to search for the executable.
source

pub fn locate<P>( &self, location: LocationType, name: P, option: LocateOption ) -> Result<Option<PathBuf>, Error>where P: AsRef<Path>,

Search for a file or directory called ‘name’ in the standard locations.

Returns a full path to the first file or directory found.

Returns Error if accessing the location failed or None if no such file or directory can be found.

Arguments
  • location - the location type where to search.
  • name - the name of the file or directory to search.
  • option - the type of entry to search.
source

pub fn locate_all<P>( &self, location: LocationType, name: P, option: LocateOption ) -> Result<Option<Vec<PathBuf>>, Error>where P: AsRef<Path>,

Search for all files or directories called ‘name’ in the standard locations.

Returns a vector of full paths to the all files or directories found.

Returns Error if accessing the location failed or None if no such files or directories can be found.

Arguments
  • location - the location type where to search.
  • name - the name of the files or directories to search.
  • option - the type of entries to search.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.