diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs index 5d854fcc5..5bb48baf0 100644 --- a/tvix/eval/src/lib.rs +++ b/tvix/eval/src/lib.rs @@ -155,21 +155,31 @@ where } impl<'co, 'ro> Evaluation<'co, 'ro, Box> { - #[cfg(feature = "impure")] - /// Initialise an `Evaluation`, with all impure features turned on by default. - pub fn new_impure() -> Self { - let mut eval = Self::new(Box::new(StdIO) as Box, true); - - eval.builtins.extend(builtins::impure_builtins()); - - eval - } - /// Initialize an `Evaluation`, without the import statement available, and /// all IO operations stubbed out. pub fn new_pure() -> Self { Self::new(Box::new(DummyIO) as Box, false) } + + #[cfg(feature = "impure")] + /// Configure an `Evaluation` to have impure features available + /// with the given I/O implementation. + /// + /// If no I/O implementation is supplied, [`StdIO`] is used by + /// default. + pub fn enable_impure(&mut self, io: Option>) { + self.io_handle = io.unwrap_or_else(|| Box::new(StdIO) as Box); + self.enable_import = true; + self.builtins.extend(builtins::impure_builtins()); + } + + #[cfg(feature = "impure")] + /// Initialise an `Evaluation`, with all impure features turned on by default. + pub fn new_impure() -> Self { + let mut eval = Self::new_pure(); + eval.enable_impure(None); + eval + } } impl<'co, 'ro, IO> Evaluation<'co, 'ro, IO>