git.delta.rocks / jrsonnet / refs/commits / 5dc3b98bcc3b

difftreelog

feat ObjValue::get_lazy

Yaroslav Bolyukin2023-07-27parent: #a51d3e5.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
390 )390 )
391 })391 })
392 }392 }
393393 pub fn get_lazy(&self, key: IStr) -> Option<Thunk<Val>> {
394 #[derive(Trace)]
395 struct ThunkGet {
396 obj: ObjValue,
397 key: IStr,
398 }
399 impl ThunkValue for ThunkGet {
400 type Output = Val;
401
402 fn get(self: Box<Self>) -> Result<Self::Output> {
403 Ok(self.obj.get(self.key)?.expect("field exists"))
404 }
405 }
406
407 if !self.has_field_ex(key.clone(), true) {
408 return None;
409 }
410 Some(Thunk::new(ThunkGet {
411 obj: self.clone(),
412 key,
413 }))
414 }
394 pub fn get(&self, key: IStr) -> Result<Option<Val>> {415 pub fn get(&self, key: IStr) -> Result<Option<Val>> {
395 self.run_assertions()?;416 self.run_assertions()?;
396 let cache_key = (key.clone(), None);417 let cache_key = (key.clone(), None);