Trait Sys

Source
pub trait Sys {
    type ReadDirEntry: SysReadDirEntry;
    type Metadata: SysMetadata;

    // Required methods
    fn is_windows(&self) -> bool;
    fn current_dir(&self) -> Result<PathBuf>;
    fn home_dir(&self) -> Option<PathBuf>;
    fn env_split_paths(&self, paths: &OsStr) -> Vec<PathBuf>;
    fn env_path(&self) -> Option<OsString>;
    fn env_path_ext(&self) -> Option<OsString>;
    fn metadata(&self, path: &Path) -> Result<Self::Metadata>;
    fn symlink_metadata(&self, path: &Path) -> Result<Self::Metadata>;
    fn read_dir(
        &self,
        path: &Path,
    ) -> Result<Box<dyn Iterator<Item = Result<Self::ReadDirEntry>>>>;
    fn is_valid_executable(&self, path: &Path) -> Result<bool>;

    // Provided method
    fn env_windows_path_ext(&self) -> Cow<'static, [String]> { ... }
}
Expand description

Represents the system that which interacts with to get information about the environment and file system.

§How to use in Wasm without WASI

WebAssembly without WASI does not have a filesystem, but using this crate is possible in wasm32-unknown-unknown targets by disabling default features:

which = { version = "...", default-features = false }
use which::WhichConfig;

struct WasmSys;

impl which::sys::Sys for WasmSys {
    // it is up to you to implement this trait based on the
    // environment you are running WebAssembly in
}

let paths = WhichConfig::new_with_sys(WasmSys)
    .all_results()
    .unwrap()
    .collect::<Vec<_>>();

Required Associated Types§

Required Methods§

Source

fn is_windows(&self) -> bool

Check if the current platform is Windows.

This can be set to true in wasm32-unknown-unknown targets that are running on Windows systems.

Source

fn current_dir(&self) -> Result<PathBuf>

Gets the current working directory.

Source

fn home_dir(&self) -> Option<PathBuf>

Gets the home directory of the current user.

Source

fn env_split_paths(&self, paths: &OsStr) -> Vec<PathBuf>

Splits a platform-specific PATH variable into a list of paths.

Source

fn env_path(&self) -> Option<OsString>

Gets the value of the PATH environment variable.

Source

fn env_path_ext(&self) -> Option<OsString>

Gets the value of the PATHEXT environment variable. If not on Windows, simply return None.

Source

fn metadata(&self, path: &Path) -> Result<Self::Metadata>

Gets the metadata of the provided path, following symlinks.

Gets the metadata of the provided path, not following symlinks.

Source

fn read_dir( &self, path: &Path, ) -> Result<Box<dyn Iterator<Item = Result<Self::ReadDirEntry>>>>

Reads the directory entries of the provided path.

Source

fn is_valid_executable(&self, path: &Path) -> Result<bool>

Checks if the provided path is a valid executable.

Provided Methods§

Source

fn env_windows_path_ext(&self) -> Cow<'static, [String]>

Gets and parses the PATHEXT environment variable on Windows.

Override this to enable caching the parsed PATHEXT.

Note: This will only be called when is_windows() returns true and isn’t conditionally compiled with #[cfg(windows)] so that it can work in Wasm.

Implementations on Foreign Types§

Source§

impl<T> Sys for &T
where T: Sys,

Implementors§