difftreelog
fix #[derive(Typed)] should lazily process Thunks
in: master
2 files changed
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth957957958 /// Tries to insert value, returns an error if it was already defined958 /// Tries to insert value, returns an error if it was already defined959 pub fn try_value(self, value: impl Into<Val>) -> Result<()> {959 pub fn try_value(self, value: impl Into<Val>) -> Result<()> {960 self.thunk(Thunk::evaluated(value.into()))960 self.try_thunk(Thunk::evaluated(value.into()))961 }961 }962 pub fn thunk(self, value: impl Into<Thunk<Val>>) -> Result<()> {962 pub fn try_thunk(self, value: impl Into<Thunk<Val>>) -> Result<()> {963 self.binding(MaybeUnbound::Bound(value.into()))963 self.binding(MaybeUnbound::Bound(value.into()))964 }964 }965 pub fn bindable(self, bindable: impl Unbound<Bound = Val>) -> Result<()> {965 pub fn bindable(self, bindable: impl Unbound<Bound = Val>) -> Result<()> {crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth477 ident: Ident,477 ident: Ident,478 ty: Type,478 ty: Type,479 is_option: bool,479 is_option: bool,480 is_lazy: bool,480}481}481impl TypedField {482impl TypedField {482 fn parse(field: &syn::Field) -> Result<Self> {483 fn parse(field: &syn::Field) -> Result<Self> {503 ));504 ));504 }505 }506507 let is_lazy = type_is_path(&ty, "Thunk").is_some();505508506 Ok(Self {509 Ok(Self {507 attr,510 attr,508 ident,511 ident,509 ty,512 ty,510 is_option,513 is_option,514 is_lazy,511 })515 })512 }516 }513 /// None if this field is flattened in jsonnet output517 /// None if this field is flattened in jsonnet output596 } else {600 } else {597 quote! {}601 quote! {}598 };602 };599 if self.is_option {603 let value = if self.is_lazy {600 quote! {604 quote! {601 if let Some(value) = self.#ident {602 out.field(#name)605 out.field(#name)603 #hide606 #hide604 #add607 #add605 .try_value(<#ty as Typed>::into_untyped(value)?)?;608 .try_thunk(<#ty as Typed>::into_lazy_untyped(value))?;606 }607 }609 }608 } else {610 } else {609 quote! {611 quote! {610 out.field(#name)612 out.field(#name)611 #hide613 #hide612 #add614 #add613 .try_value(<#ty as Typed>::into_untyped(self.#ident)?)?;615 .try_value(<#ty as Typed>::into_untyped(value)?)?;614 }616 }615 }617 };618 if self.is_option {619 quote! {620 if let Some(value) = self.#ident {621 #value622 }623 }624 } else {625 quote! {626 {627 let value = self.#ident;628 #value629 }630 }631 }616 },632 },617 )633 )618 }634 }