use std::any::{Any, TypeId};
use std::ops::Deref;
pub struct InvocationInfo<'a> {
pub func_name: &'a str,
pub arg_names: &'a[&'a str],
pub arg_values: &'a [Box<dyn Any>],
pub return_type: TypeId,
pub return_value: Option<Box<dyn Any>>
}
pub trait DynamicProxy {
fn call(&self, invocation: &mut InvocationInfo);
}
impl<'a> InvocationInfo<'a> {
pub fn set_return_value<T: 'static>(&mut self, val: T) {
let result: Box<dyn Any> = Box::new(val);
self.return_value = Some(result);
}
pub fn get_arg_value<T: 'static>(&self, index: usize) -> &T {
self.arg_values[index].downcast_ref::<T>().unwrap()
}
pub fn get_arg_type(&self, index: usize) -> TypeId {
self.arg_values[index].deref().type_id()
}
}