From 5dc3b98bcc3b9848031f17165bcc2e86e8a65ba3 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 27 Jul 2023 14:23:51 +0000 Subject: [PATCH] feat: ObjValue::get_lazy --- --- 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); -- gitstuff