Created
August 26, 2016 02:39
-
-
Save Stebalien/9300b28e0aedd2096d9a233bd89e4edc 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
#![feature(specialization, never_type)] | |
use std::rc::Rc; | |
use std::sync::Arc; | |
pub trait Identity { | |
type Type: ?Sized; | |
fn identity(&self) -> *const (); | |
} | |
impl<T: ?Sized> Identity for T { | |
default type Type = Self; | |
default fn identity(&self) -> *const () { | |
self as *const Self as *const () | |
} | |
} | |
impl<T: ?Sized> Identity for Box<T> { | |
type Type = <T as Identity>::Type; | |
fn identity(&self) -> *const () { | |
(**self).identity() | |
} | |
} | |
impl<'a, T: ?Sized> Identity for &'a T { | |
type Type = <T as Identity>::Type; | |
fn identity(&self) -> *const () { | |
(**self).identity() | |
} | |
} | |
impl<'a, T: ?Sized> Identity for &'a mut T { | |
type Type = <T as Identity>::Type; | |
fn identity(&self) -> *const () { | |
(**self).identity() | |
} | |
} | |
impl<T: ?Sized> Identity for Rc<T> { | |
type Type = <T as Identity>::Type; | |
fn identity(&self) -> *const () { | |
(**self).identity() | |
} | |
} | |
impl<T: ?Sized> Identity for Arc<T> { | |
type Type = <T as Identity>::Type; | |
fn identity(&self) -> *const () { | |
(**self).identity() | |
} | |
} | |
pub fn same<A: Identity, B: Identity<Type=A::Type>>(a: &A, b: &B) -> bool { | |
a.identity() == b.identity() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment