Open nikomatsakis opened 7 years ago
Delegation traits (Code stolen from EddyB)
// Potentially somewhere central, or generated per-trait.
trait Delegate/*Health*/ {
type Delegatee;
delegatee: Self::Delegatee;
}
impl<T: Delegate/*Health*/> Health for T
where T::Delegatee: Health
{
fn health(&self) -> u8 {
self.delegatee.health()
}
}
impl Delegate/*Health*/ for Player {
delegatee => self.health;
}
https://github.com/rust-lang/rfcs/pull/2393#issuecomment-391978163
It'd be great to accumulate more use-cases.
Open thread for suggestions. =)