git.delta.rocks / jrsonnet / refs/commits / 32a7ddca0d3c

difftreelog

source

crates/jrsonnet-evaluator/src/native.rs592 Bsourcehistory
1use crate::{error::Result, Val};2use jrsonnet_parser::ParamsDesc;3use std::fmt::Debug;45pub struct NativeCallback {6	pub params: ParamsDesc,7	handler: Box<dyn Fn(&[Val]) -> Result<Val>>,8}9impl NativeCallback {10	pub fn new(params: ParamsDesc, handler: impl Fn(&[Val]) -> Result<Val> + 'static) -> Self {11		Self {12			params,13			handler: Box::new(handler),14		}15	}16	pub fn call(&self, args: &[Val]) -> Result<Val> {17		(self.handler)(args)18	}19}20impl Debug for NativeCallback {21	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {22		f.debug_struct("NativeCallback").finish()23	}24}