Trait tvix_eval::io::EvalIO

source ·
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§

source

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
source

fn open(&self, path: &Path) -> Result<Box<dyn Read>>

Open the file at the specified path to a io::Read.

source

fn file_type(&self, path: &Path) -> Result<FileType>

Return the FileType of the given path, or an error if it doesn’t exist.

source

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>
source

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

Provided Methods§

source

fn store_dir(&self) -> Option<String>

Returns the root of the store directory, if such a thing exists in the evaluation context.

This is used for the following language evaluation cases:

  • builtins.storeDir :: string

Implementors§