Struct tvix_eval::Evaluation

source ·
pub struct Evaluation<'co, 'ro, 'env, IO> {
    pub(crate) source_map: SourceCode,
    pub(crate) globals: Rc<GlobalsMap>,
    pub(crate) env: Option<&'env FxHashMap<SmolStr, Value>>,
    pub(crate) io_handle: IO,
    pub(crate) strict: bool,
    pub(crate) nix_path: Option<String>,
    pub(crate) compiler_observer: Option<&'co mut dyn CompilerObserver>,
    pub(crate) 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.

Fields§

§source_map: SourceCode

Source code map used for error reporting.

§globals: Rc<GlobalsMap>

Set of all global values available at the top-level scope

§env: Option<&'env FxHashMap<SmolStr, Value>>

Top-level variables to define in the evaluation

§io_handle: IO

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

Defaults to DummyIO if not set explicitly.

§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.

Implementations§

source§

impl<'co, 'ro, 'env, IO> Evaluation<'co, 'ro, 'env, IO>

source

pub fn builder(io_handle: IO) -> EvaluationBuilder<'co, 'ro, 'env, IO>

Make a new builder for configuring an evaluation

source

pub fn globals(&self) -> Rc<GlobalsMap>

Clone the reference to the map of Nix globals for this evaluation. If Values are shared across subsequent Evaluations, it is important that those evaluations all have the same underlying globals map.

source

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. Also, if Values are shared across subsequent Evaluations, it is important that those evaluations all have the same underlying source code map.

source§

impl<'co, 'ro, 'env> Evaluation<'co, 'ro, 'env, Box<dyn EvalIO>>

source

pub fn builder_impure() -> EvaluationBuilder<'co, 'ro, 'env, Box<dyn EvalIO>>

source

pub fn builder_pure() -> EvaluationBuilder<'co, 'ro, 'env, Box<dyn EvalIO>>

source§

impl<'co, 'ro, 'env, IO> Evaluation<'co, 'ro, 'env, IO>
where IO: AsRef<dyn EvalIO> + 'static,

source

pub fn compile_only( self, code: impl AsRef<str>, location: Option<PathBuf>, ) -> EvaluationResult

Only compile the provided source code, at an 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) This does not run the code, it only provides analysis (errors and warnings) of the compiler.

source

pub fn evaluate( self, code: impl AsRef<str>, location: Option<PathBuf>, ) -> EvaluationResult

Evaluate the provided source code, at an 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)

Auto Trait Implementations§

§

impl<'co, 'ro, 'env, IO> Freeze for Evaluation<'co, 'ro, 'env, IO>
where IO: Freeze,

§

impl<'co, 'ro, 'env, IO> !RefUnwindSafe for Evaluation<'co, 'ro, 'env, IO>

§

impl<'co, 'ro, 'env, IO> !Send for Evaluation<'co, 'ro, 'env, IO>

§

impl<'co, 'ro, 'env, IO> !Sync for Evaluation<'co, 'ro, 'env, IO>

§

impl<'co, 'ro, 'env, IO> Unpin for Evaluation<'co, 'ro, 'env, IO>
where IO: Unpin,

§

impl<'co, 'ro, 'env, IO> !UnwindSafe for Evaluation<'co, 'ro, 'env, IO>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

source§

fn vzip(self) -> V