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§
Sourcefn is_windows(&self) -> bool
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.
Sourcefn current_dir(&self) -> Result<PathBuf>
fn current_dir(&self) -> Result<PathBuf>
Gets the current working directory.
Sourcefn env_split_paths(&self, paths: &OsStr) -> Vec<PathBuf>
fn env_split_paths(&self, paths: &OsStr) -> Vec<PathBuf>
Splits a platform-specific PATH variable into a list of paths.
Sourcefn env_path_ext(&self) -> Option<OsString>
fn env_path_ext(&self) -> Option<OsString>
Gets the value of the PATHEXT environment variable. If not on Windows, simply return None.
Sourcefn metadata(&self, path: &Path) -> Result<Self::Metadata>
fn metadata(&self, path: &Path) -> Result<Self::Metadata>
Gets the metadata of the provided path, following symlinks.
Sourcefn symlink_metadata(&self, path: &Path) -> Result<Self::Metadata>
fn symlink_metadata(&self, path: &Path) -> Result<Self::Metadata>
Gets the metadata of the provided path, not following symlinks.
Sourcefn read_dir(
&self,
path: &Path,
) -> Result<Box<dyn Iterator<Item = Result<Self::ReadDirEntry>>>>
fn read_dir( &self, path: &Path, ) -> Result<Box<dyn Iterator<Item = Result<Self::ReadDirEntry>>>>
Reads the directory entries of the provided path.
Sourcefn is_valid_executable(&self, path: &Path) -> Result<bool>
fn is_valid_executable(&self, path: &Path) -> Result<bool>
Checks if the provided path is a valid executable.
Provided Methods§
Sourcefn env_windows_path_ext(&self) -> Cow<'static, [String]>
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.