1#![allow(clippy::type_complexity)]23use crate::gc::TraceBox;4use crate::{error::Result, Val};5use gcmodule::Trace;6use jrsonnet_parser::ParamsDesc;7use std::fmt::Debug;8use std::path::Path;9use std::rc::Rc;1011pub trait NativeCallbackHandler: Trace {12 fn call(&self, from: Rc<Path>, args: &[Val]) -> Result<Val>;13}1415#[derive(Trace)]16pub struct NativeCallback {17 pub params: ParamsDesc,18 handler: TraceBox<dyn NativeCallbackHandler>,19}20impl NativeCallback {21 pub fn new(params: ParamsDesc, handler: TraceBox<dyn NativeCallbackHandler>) -> Self {22 Self { params, handler }23 }24 pub fn call(&self, caller: 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}