use dyn_derive::*; use dyn_std::Instance; #[dyn_trait] pub trait Meta: Clone { fn method_1(arg1: T, arg2: Self, arg3: &Self, arg4: Box) -> Self; fn method_3(arg1: Vec, arg2: Vec<&Self>) -> bool; fn method_4(arg1: Option, arg2: Option<&Self>) -> Option; fn method_5(arg1: Result, arg2: Result<(), &Self>) -> Self; fn method_6(&self, arg1: &dyn Fn(Self) -> Self) -> Self; fn method_7(&self, arg1: Vec Self>>) -> Self; } #[derive(Clone)] struct MetaImpl(T); impl MetaFactory for MetaImpl { fn method_1(arg1: T, _arg2: Self, _arg3: &Self, _arg4: Box) -> Self { MetaImpl(arg1) } fn method_3(arg1: Vec, arg2: Vec<&Self>) -> bool { arg1.len() == arg2.len() } fn method_4(arg1: Option, _arg2: Option<&Self>) -> Option { arg1 } fn method_5(arg1: Result, _arg2: Result<(), &Self>) -> Self { arg1.unwrap() } fn method_6(&self, arg1: &dyn Fn(Self) -> Self) -> Self { arg1(self.clone()) } fn method_7(&self, mut arg1: Vec Self>>) -> Self { arg1[0](self.clone()) } } #[test] fn main() { let instance: Box> = Box::new(Instance::new(MetaImpl(42))); instance.method_1(0, instance.clone(), instance.as_ref(), instance.clone()); instance.method_3(vec![instance.clone()], vec![instance.as_ref()]); instance.method_4(Some(instance.clone()), Some(instance.as_ref())); instance.method_5(Ok(instance.clone()), Err(instance.as_ref())); instance.method_6(&mut |x| x); }