use std::{marker::PhantomData, ops::Add}; use auto_delegate::{delegate, Delegate}; #[delegate] trait Addr> where X: Add, { fn add(&mut self, x: X, y: Y) -> X; } struct Child> where X: Add, { _maker: PhantomData, _maker2: PhantomData, } impl> Addr for Child where X: Add, { fn add(&mut self, x: X, y: Y) -> X { x + y } } #[derive(Delegate)] struct Parent> where X: Add, { #[to(Addr)] child: Child, } fn main() { let mut parent = Parent { child: Child { _maker: PhantomData, _maker2: PhantomData, }, }; assert_eq!(parent.add(2, 3), 5); }