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

difftreelog

source

crates/jrsonnet-evaluator/src/function/native.rs971 Bsourcehistory
1use super::{arglike::ArgLike, CallLocation, FuncVal};2use crate::{error::Result, typed::Typed, 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						s.create_default_context(),23						CallLocation::native(),24						&($($gen,)*),25						true26					)?;27					O::from_untyped(val, s.clone())28				})29			}30		}31	};32	($($cur:ident)* @ $c:ident $($rest:ident)*) => {33		impl_native_desc!($($cur)*);34		impl_native_desc!($($cur)* $c @ $($rest)*);35	};36	($($cur:ident)* @) => {37		impl_native_desc!($($cur)*);38	}39}4041impl_native_desc! {42	@ A B C D E F G H I J K L43}