Skip to content

Instantly share code, notes, and snippets.

@ErnWong
Created June 22, 2021 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErnWong/af2043f0e5e29d3e19ac8bf757b6f3dd to your computer and use it in GitHub Desktop.
Save ErnWong/af2043f0e5e29d3e19ac8bf757b6f3dd to your computer and use it in GitHub Desktop.
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