1use crate::{error::Result, Val};2use jrsonnet_parser::ParamsDesc;3use std::fmt::Debug;4use std::path::PathBuf;5use std::rc::Rc;67pub struct NativeCallback {8 pub params: ParamsDesc,9 handler: Box<dyn Fn(Option<Rc<PathBuf>>, &[Val]) -> Result<Val>>,10}11impl NativeCallback {12 pub fn new(13 params: ParamsDesc,14 handler: impl Fn(Option<Rc<PathBuf>>, &[Val]) -> Result<Val> + 'static,15 ) -> Self {16 Self {17 params,18 handler: Box::new(handler),19 }20 }21 pub fn call(&self, caller: Option<Rc<PathBuf>>, args: &[Val]) -> Result<Val> {22 (self.handler)(caller, args)23 }24}25impl Debug for NativeCallback {26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {27 f.debug_struct("NativeCallback").finish()28 }29}