Created
June 22, 2021 07:30
-
-
Save ErnWong/af2043f0e5e29d3e19ac8bf757b6f3dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait X { | |
type X; | |
fn f() -> Self::X; | |
} | |
trait Y { | |
type Y; | |
fn f(y: Self::Y); | |
} | |
trait XY { | |
type X: X; | |
type Y: Y<Y=<Self::X as X>::X>; | |
} | |
fn a<XYType:XY>() { | |
XYType::Y::f(XYType::X::f()); | |
} | |
#[derive(Debug)] | |
struct TheType(usize); | |
impl X for TheType { | |
type X = Self; | |
fn f() -> Self::X { | |
TheType(42) | |
} | |
} | |
impl Y for TheType { | |
type Y = Self; | |
fn f(y: Self::Y) { | |
println!("{:?}", y); | |
} | |
} | |
impl XY for TheType { | |
type X = Self; | |
type Y = Self; | |
} | |
fn main() { | |
a::<TheType>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment