Struct tvix_eval::Evaluation

source ·
pub struct Evaluation<'code, 'co, 'ro> {
    pub(crate) code: &'code str,
    pub(crate) location: Option<PathBuf>,
    pub(crate) source_map: SourceCode,
    pub(crate) file: Arc<File>,
    pub builtins: Vec<(&'static str, Value)>,
    pub src_builtins: Vec<(&'static str, &'static str)>,
    pub io_handle: Box<dyn EvalIO>,
    pub enable_import: bool,
    pub strict: bool,
    pub nix_path: Option<String>,
    pub compiler_observer: Option<&'co mut dyn CompilerObserver>,
    pub runtime_observer: Option<&'ro mut dyn RuntimeObserver>,
Expand description

An Evaluation represents how a piece of Nix code is evaluated. It can be instantiated and configured directly, or it can be accessed through the various simplified helper methods available below.

Public fields are intended to be set by the caller. Setting all fields is optional.


§code: &'code str

The Nix source code to be evaluated.

§location: Option<PathBuf>

Optional location of the source code (i.e. path to the file it was read from). Used for error reporting, and for resolving relative paths in impure functions.

§source_map: SourceCode

Source code map used for error reporting.

§file: Arc<File>

Top-level file reference for this code inside the source map.

§builtins: Vec<(&'static str, Value)>

Set of all builtins that should be available during the evaluation.

This defaults to all pure builtins. Users might want to add the set of impure builtins, or other custom builtins.

§src_builtins: Vec<(&'static str, &'static str)>

Set of builtins that are implemented in Nix itself and should be compiled and inserted in the builtins set.

§io_handle: Box<dyn EvalIO>

Implementation of file-IO to use during evaluation, e.g. for impure builtins.

Defaults to DummyIO if not set explicitly.

§enable_import: bool

Determines whether the import builtin should be made available. Note that this depends on the io_handle being able to read the files specified as arguments to import.

§strict: bool

Determines whether the returned value should be strictly evaluated, that is whether its list and attribute set elements should be forced recursively.

§nix_path: Option<String>

(optional) Nix search path, e.g. the value of NIX_PATH used for resolving items on the search path (such as <nixpkgs>).

§compiler_observer: Option<&'co mut dyn CompilerObserver>

(optional) compiler observer for reporting on compilation details, like the emitted bytecode.

§runtime_observer: Option<&'ro mut dyn RuntimeObserver>

(optional) runtime observer, for reporting on execution steps of Nix code.



impl<'code, 'co, 'ro> Evaluation<'code, 'co, 'ro>


pub fn new(code: &'code str, location: Option<PathBuf>) -> Self

Initialise an Evaluation for the given Nix source code snippet, and an optional code location.


pub fn new_impure(code: &'code str, location: Option<PathBuf>) -> Self

Initialise an Evaluation for the given snippet, with all impure features turned on by default.


pub fn source_map(&self) -> SourceCode

Clone the reference to the contained source code map. This is used after an evaluation for pretty error printing.


pub fn compile_only(self) -> EvaluationResult

Only compile the provided source code. This does not run the code, it only provides analysis (errors and warnings) of the compiler.


pub fn evaluate(self) -> EvaluationResult

Evaluate the provided source code.

Auto Trait Implementations§


impl<'code, 'co, 'ro> !RefUnwindSafe for Evaluation<'code, 'co, 'ro>


impl<'code, 'co, 'ro> !Send for Evaluation<'code, 'co, 'ro>


impl<'code, 'co, 'ro> !Sync for Evaluation<'code, 'co, 'ro>


impl<'code, 'co, 'ro> Unpin for Evaluation<'code, 'co, 'ro>


impl<'code, 'co, 'ro> !UnwindSafe for Evaluation<'code, 'co, 'ro>

Blanket Implementations§


impl<T> Any for Twhere T: 'static + ?Sized,


fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more

impl<T> Borrow<T> for Twhere T: ?Sized,


fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for Twhere T: ?Sized,


fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more

impl<T> From<T> for T


fn from(t: T) -> T

Returns the argument unchanged.


impl<T, U> Into<U> for Twhere U: From<T>,


fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.


impl<T, U> TryFrom<U> for Twhere U: Into<T>,


type Error = Infallible

The type returned in the event of a conversion error.

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,


type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,


fn vzip(self) -> V