git.delta.rocks / jrsonnet / refs/commits / a2ae6ff1c0dc

difftreelog

source

crates/jrsonnet-evaluator/src/native.rs829 Bsourcehistory
1#![allow(clippy::type_complexity)]23use crate::{error::Result, Val};4use gc::{Finalize, 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, Finalize)]15pub struct NativeCallback {16	pub params: ParamsDesc,17	handler: Box<dyn NativeCallbackHandler>,18}19impl NativeCallback {20	pub fn new(params: ParamsDesc, handler: Box<dyn NativeCallbackHandler>) -> Self {21		Self { params, handler }22	}23	pub fn call(&self, caller: Option<Rc<Path>>, args: &[Val]) -> Result<Val> {24		self.handler.call(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}