Skip to content

Instantly share code, notes, and snippets.

Created May 7, 2016 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7c081574958d22f89d434a97b626b1e4 to your computer and use it in GitHub Desktop.
Save anonymous/7c081574958d22f89d434a97b626b1e4 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#![feature(specialization)]
pub trait NotSame {}
pub struct True;
pub struct False;
pub trait Sameness {
type Same;
}
mod internal {
pub trait PrivSameness {
type Same;
}
}
use internal::PrivSameness;
impl<A, B> Sameness for (A, B) {
type Same = <Self as PrivSameness>::Same;
}
impl<A, B> PrivSameness for (A, B) {
default type Same = False;
}
impl<A> PrivSameness for (A, A) {
type Same = True;
}
impl<A, B> NotSame for (A, B) where (A, B): Sameness<Same=False> {}
fn not_same<A, B>() where (A, B): NotSame {}
fn main() {
not_same::<i32, f32>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment