Trait grass::Fs

source ·
pub trait Fs: Debug {
    fn is_dir(&self, path: &Path) -> bool;
    fn is_file(&self, path: &Path) -> bool;
    fn read(&self, path: &Path) -> Result<Vec<u8>>;
}
Expand description

A trait to allow replacing the file system lookup mechanisms.

As it stands, this is imperfect: it’s still using the types and some operations from std::path, which constrain it to the target platform’s norms. This could be ameliorated by the use of associated types for Path and PathBuf, and putting all remaining methods on this trait (is_absolute, parent, join, &c.); but that would infect too many other APIs to be desirable, so we live with it as it is—which is also acceptable, because the motivating example use case is mostly using this as an optimisation over the real platform underneath.

Required Methods§

Returns true if the path exists on disk and is pointing at a directory.

Returns true if the path exists on disk and is pointing at a regular file.

Read the entire contents of a file into a bytes vector.

Implementors§