pub trait EvalIO {
// Required methods
fn path_exists(&self, path: &Path) -> Result<bool>;
fn open(&self, path: &Path) -> Result<Box<dyn Read>>;
fn file_type(&self, path: &Path) -> Result<FileType>;
fn read_dir(&self, path: &Path) -> Result<Vec<(Bytes, FileType)>>;
fn import_path(&self, path: &Path) -> Result<PathBuf>;
// Provided method
fn store_dir(&self) -> Option<String> { ... }
}
Expand description
Represents all possible filesystem interactions that exist in the Nix language, and that need to be executed somehow.
This trait is specifically only concerned with what is visible on the level of the language. All internal implementation details are not part of this trait.
Required Methods§
sourcefn path_exists(&self, path: &Path) -> Result<bool>
fn path_exists(&self, path: &Path) -> Result<bool>
Verify whether the file at the specified path exists.
This is used for the following language evaluation cases:
- checking whether a file added to the
NIX_PATH
actually exists when it is referenced in<...>
brackets. builtins.pathExists :: path -> bool
sourcefn open(&self, path: &Path) -> Result<Box<dyn Read>>
fn open(&self, path: &Path) -> Result<Box<dyn Read>>
Open the file at the specified path to a io::Read
.
sourcefn file_type(&self, path: &Path) -> Result<FileType>
fn file_type(&self, path: &Path) -> Result<FileType>
Return the FileType of the given path, or an error if it doesn’t exist.
sourcefn read_dir(&self, path: &Path) -> Result<Vec<(Bytes, FileType)>>
fn read_dir(&self, path: &Path) -> Result<Vec<(Bytes, FileType)>>
Read the directory at the specified path and return the names
of its entries associated with their FileType
.
This is used for the following language evaluation cases:
builtins.readDir :: path -> attrs<filename, filetype>
sourcefn import_path(&self, path: &Path) -> Result<PathBuf>
fn import_path(&self, path: &Path) -> Result<PathBuf>
Import the given path. What this means depends on the implementation,
for example for a std::io
-based implementation this might be a no-op,
while for a Tvix store this might be a copy of the given files to the
store.
This is used for the following language evaluation cases:
- string coercion of path literals (e.g.
/foo/bar
), which are expected to return a path builtins.toJSON
on a path literal, also expected to return a path