macro_rules! access { ($instance: expr, $trait: path, $with: expr) => { { fn get_thing(instance: &T) { $with(::Type) } get_thing($instance) } } } struct Cat; struct Dog; trait Animal { type Type; } impl Animal for Cat { type Type = u32; } impl Animal for Dog { type Type = i64; } trait MaxAndMin { type Type; const MAXIMUM: Self::Type; const MINIMUM: Self::Type; } impl MaxAndMin for u32 { type Type = u32; const MAXIMUM: Self::Type = u32::MAX; const MINIMUM: Self::Type = u32::MIN; } impl MaxAndMin for i64 { type Type = i64; const MAXIMUM: Self::Type = i64::MAX; const MINIMUM: Self::Type = i64::MIN; } fn main() { let katniss = Cat; let lola = Dog; fn get_min(instance: &T) -> <::Type as MaxAndMin>::Type where T::Type: MaxAndMin { ::MINIMUM } let katniss_max = get_min(&katniss); let lola_max = get_min(&lola); println!("{katniss_max}"); println!("{lola_max}"); // let max = access!(&katniss, Animal, ::MAX); // println!("{legs}"); }