git.delta.rocks / jrsonnet / refs/commits / ff3e2c836938

difftreelog

source

crates/jrsonnet-evaluator/src/function/native.rs1.0 KiBsourcehistory
1use super::{arglike::ArgLike, CallLocation, FuncVal};2use crate::{error::Result, typed::Typed, Context, State};34pub trait NativeDesc {5	type Value;6	fn into_native(val: FuncVal) -> Self::Value;7}8macro_rules! impl_native_desc {9	($($gen:ident)*) => {10		impl<$($gen,)* O> NativeDesc for (($($gen,)*), O)11		where12			$($gen: ArgLike,)*13			O: Typed,14		{15			type Value = Box<dyn Fn(State, $($gen,)*) -> Result<O>>;1617			#[allow(non_snake_case)]18			fn into_native(val: FuncVal) -> Self::Value {19				Box::new(move |s: State, $($gen),*| {20					let val = val.evaluate(21						s.clone(),22						// This isn't intended to be used with ArgsDesc23						Context::default(),24						CallLocation::native(),25						&($($gen,)*),26						true27					)?;28					O::from_untyped(val, s.clone())29				})30			}31		}32	};33	($($cur:ident)* @ $c:ident $($rest:ident)*) => {34		impl_native_desc!($($cur)*);35		impl_native_desc!($($cur)* $c @ $($rest)*);36	};37	($($cur:ident)* @) => {38		impl_native_desc!($($cur)*);39	}40}4142impl_native_desc! {43	@ A B C D E F G H I J K L44}