use std::{marker::PhantomData, ops::Add}; use auto_delegate::{delegate, Delegate}; #[delegate] trait Addr> { fn add(&mut self, x1: Num, x2: Num) -> Num; } struct Child> { _maker: PhantomData, } impl> Addr for Child { fn add(&mut self, x1: Num, x2: Num) -> Num { x1 + x2 } } #[derive(Delegate)] struct Parent> { #[to(Addr)] child: Child, } impl> Parent { pub fn new() -> Parent { Self { child: Child { _maker: PhantomData, }, } } } fn main() { let mut parent = Parent::::new(); let num = parent.add(3, 5); assert_eq!(num, 8); }