--- a/crates/jrsonnet-evaluator/src/obj.rs +++ b/crates/jrsonnet-evaluator/src/obj.rs @@ -390,7 +390,28 @@ ) }) } + pub fn get_lazy(&self, key: IStr) -> Option> { + #[derive(Trace)] + struct ThunkGet { + obj: ObjValue, + key: IStr, + } + impl ThunkValue for ThunkGet { + type Output = Val; + fn get(self: Box) -> Result { + Ok(self.obj.get(self.key)?.expect("field exists")) + } + } + + if !self.has_field_ex(key.clone(), true) { + return None; + } + Some(Thunk::new(ThunkGet { + obj: self.clone(), + key, + })) + } pub fn get(&self, key: IStr) -> Result> { self.run_assertions()?; let cache_key = (key.clone(), None);