--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs +++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs @@ -128,8 +128,7 @@ new_bindings, )?; } - Some(DestructRest::Drop) => {} - None => {} + Some(DestructRest::Drop) | None => {} } { @@ -202,7 +201,7 @@ .collect(); let full = Thunk::new(tb!(DataThunk { parent, - field_names: field_names.clone(), + field_names, has_rest: rest.is_some() })); @@ -222,7 +221,7 @@ Ok(field) } else { let (fctx, expr) = self.default.as_ref().expect("shape is checked"); - Ok(evaluate(fctx.clone().unwrap(), &expr)?) + Ok(evaluate(fctx.clone().unwrap(), expr)?) } } } --- a/crates/jrsonnet-evaluator/src/lib.rs +++ b/crates/jrsonnet-evaluator/src/lib.rs @@ -44,6 +44,8 @@ extern crate self as jrsonnet_evaluator; mod arr; +#[cfg(feature = "async-import")] +pub mod async_import; mod ctx; mod dynamic; pub mod error; @@ -188,6 +190,18 @@ evaluating: false, } } + pub(crate) fn get_string(&mut self) -> Option { + if self.string.is_none() { + self.string = Some( + self.bytes + .as_ref() + .expect("either string or bytes should be set") + .clone() + .cast_str()?, + ); + } + Some(self.string.clone().expect("just set")) + } } #[derive(Default, Trace)] @@ -223,20 +237,9 @@ .1 } }; - if let Some(str) = &file.string { - return Ok(str.clone()); - } - if file.string.is_none() { - file.string = Some( - file.bytes - .as_ref() - .expect("either string or bytes should be set") - .clone() - .cast_str() - .ok_or_else(|| ImportBadFileUtf8(path.clone()))?, - ); - } - Ok(file.string.as_ref().expect("just set").clone()) + Ok(file + .get_string() + .ok_or_else(|| ImportBadFileUtf8(path.clone()))?) } /// Should only be called with path retrieved from [`resolve_path`], may panic otherwise pub fn import_resolved_bin(&self, path: SourcePath) -> Result { @@ -288,23 +291,14 @@ if let Some(val) = &file.evaluated { return Ok(val.clone()); } - if file.string.is_none() { - file.string = Some( - std::str::from_utf8( - file.bytes - .as_ref() - .expect("either string or bytes should be set"), - ) - .map_err(|_| ImportBadFileUtf8(path.clone()))? - .into(), - ); - } - let code = file.string.as_ref().expect("just set"); + let code = file + .get_string() + .ok_or_else(|| ImportBadFileUtf8(path.clone()))?; let file_name = Source::new(path.clone(), code.clone()); if file.parsed.is_none() { file.parsed = Some( jrsonnet_parser::parse( - code, + &code, &ParserSettings { source: file_name.clone(), },