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