git.delta.rocks / jrsonnet / refs/commits / 078724755e3c

difftreelog

source

crates/jsonnet-evaluator/src/binding.rs1.1 KiBsourcehistory
1use crate::{2	ArgsBindingLazyVal, BoxedContextCreator, BoxedLazyVal, NoArgsBindingLazyVal, ObjValue, Val,3};4use jsonnet_parser::{Expr, ParamsDesc};5use std::{fmt::Debug, rc::Rc};67pub trait Binding: Debug {8	fn evaluate(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Val;9}10pub type BoxedBinding = Rc<dyn Binding>;1112#[derive(Debug)]13pub struct NoArgsBinding {14	pub expr: Expr,15	pub context_creator: BoxedContextCreator,16}17impl Binding for NoArgsBinding {18	fn evaluate(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Val {19		Val::Lazy(BoxedLazyVal(Rc::new(NoArgsBindingLazyVal {20			context_creator: self.context_creator.clone(),21			expr: self.expr.clone(),22			this,23			super_obj,24		})))25	}26}27#[derive(Debug)]28pub struct ArgsBinding {29	pub expr: Expr,30	pub args: ParamsDesc,31	pub context_creator: BoxedContextCreator,32}33impl Binding for ArgsBinding {34	fn evaluate(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Val {35		Val::Lazy(BoxedLazyVal(Rc::new(ArgsBindingLazyVal {36			context_creator: self.context_creator.clone(),37			expr: self.expr.clone(),38			args: self.args.clone(),39			this,40			super_obj,41		})))42	}43}