use std::fmt::{Debug, Display}; // Done struct MatchTypeDone(T); impl MatchTypeDone { // fn match_type_w0(self) -> Self { // self // } fn match_type_w1(self) -> Self { self } fn match_type_w2(self) -> Self { self } fn match_type_finish(self) -> T { self.0 } } // 0 trait MatchTypeMatch0 { type MatchTypeReturnType; fn match_type_m0(self) -> Self::MatchTypeReturnType; } struct MatchTypeWrapper0(T); impl MatchTypeWrapper0 { fn match_type_w0(self) -> MatchTypeDone<::MatchTypeReturnType> { MatchTypeDone(MatchTypeMatch0::match_type_m0(self.0)) } } trait MatchTypeCatch0 { type MatchTypeReturnType; fn match_type_w0(self) -> Self::MatchTypeReturnType; } impl MatchTypeCatch0 for T { type MatchTypeReturnType = MatchTypeWrapper1; fn match_type_w0(self) -> Self::MatchTypeReturnType { MatchTypeWrapper1(self) } } impl MatchTypeMatch0 for T { type MatchTypeReturnType = String; fn match_type_m0(self) -> Self::MatchTypeReturnType { format!("{}", self) } } // 1 trait MatchTypeMatch1 { type MatchTypeReturnType; fn match_type_m1(self) -> Self::MatchTypeReturnType; } struct MatchTypeWrapper1(T); impl MatchTypeWrapper1 { fn match_type_w1(self) -> MatchTypeDone<::MatchTypeReturnType> { MatchTypeDone(MatchTypeMatch1::match_type_m1(self.0)) } } trait MatchTypeCatch1 { type MatchTypeReturnType; fn match_type_w1(self) -> Self::MatchTypeReturnType; } impl MatchTypeCatch1 for T { type MatchTypeReturnType = MatchTypeWrapper2; fn match_type_w1(self) -> Self::MatchTypeReturnType { MatchTypeWrapper2(self) } } impl MatchTypeMatch1 for MatchTypeWrapper1> { type MatchTypeReturnType = String; fn match_type_m1(self) -> Self::MatchTypeReturnType { format!("{:?}", self.0 .0) } } // 2 trait MatchTypeMatch2 { type MatchTypeReturnType; fn match_type_m2(self) -> Self::MatchTypeReturnType; } struct MatchTypeWrapper2(T); impl MatchTypeWrapper2 { fn match_type_w2(self) -> MatchTypeDone<::MatchTypeReturnType> { MatchTypeDone(MatchTypeMatch2::match_type_m2(self.0)) } } trait MatchTypeCatch2 { type MatchTypeReturnType; fn match_type_w2(self) -> Self::MatchTypeReturnType; } impl MatchTypeCatch2 for T { type MatchTypeReturnType = MatchTypeWrapper3; fn match_type_w2(self) -> Self::MatchTypeReturnType { MatchTypeWrapper3(self) } } impl MatchTypeMatch2 for MatchTypeWrapper2> { type MatchTypeReturnType = &'static str; fn match_type_m2(self) -> Self::MatchTypeReturnType { "Sad Monkey :(" } } struct MatchTypeWrapper3(T); impl MatchTypeWrapper3 { fn match_type_finish(self) -> ! { unimplemented!() } } //===============================================// macro_rules! m { ($e:expr) => { (MatchTypeWrapper0($e) .match_type_w0() .match_type_w1() .match_type_w2() .match_type_finish()) }; } struct S(); fn main() { let q = MatchTypeWrapper0(vec![1, 2, 3]) .match_type_w0() .match_type_w1() .match_type_w2(); // .match_type_finish(); let i = 1729; let v = vec![0, 1, 2]; let s = S(); let x = m!(&i); let y = m!(&v); let z = m!(&s); // println!("{}\n{}\n{}", x, y, z); println!("{:?}", &v); }