about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/lib.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs
index 5d854fcc5f07..5bb48baf055d 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<dyn EvalIO>> {
-    #[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<dyn EvalIO>, 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<dyn EvalIO>, 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<Box<dyn EvalIO>>) {
+        self.io_handle = io.unwrap_or_else(|| Box::new(StdIO) as Box<dyn EvalIO>);
+        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>