refactor(tvix/eval): add API for enabling impure evaluation features
This makes some of the work of configuring an arbitrary I/O handler easier. Change-Id: I158db3235fe83df6e709578ed515e0e028c20086 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10959 Reviewed-by: flokli <flokli@flokli.de> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
db26cb2132
commit
2277e62c2d
1 changed files with 20 additions and 10 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue