pub trait TakeRecur {
type Inner;
// Required method
fn take_recur(self) -> Self::Inner;
}Expand description
A trait for taking inner value out.
Various types have methods like take() to take something out by consuming
the type itself. If the taken value also can be unwrapped, then clients
need to write code like take().take(). This trait helps to avoid something
like that and replace it with just one call.
§Examples
use my_ecs::prelude::TakeRecur;
struct A(B);
struct B(C);
struct C(i32);
impl TakeRecur for A
where
B: TakeRecur
{
type Inner = <B as TakeRecur>::Inner;
fn take_recur(self) -> Self::Inner { self.0.take_recur() }
}
impl TakeRecur for B
where
C: TakeRecur,
{
type Inner = <C as TakeRecur>::Inner;
fn take_recur(self) -> Self::Inner { self.0.take_recur() }
}
impl TakeRecur for C {
type Inner = i32;
fn take_recur(self) -> Self::Inner { self.0 }
}
let value = A(B(C(42)));
assert_eq!(value.take_recur(), 42);