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