SHARE
TWEET

Untitled

a guest Apr 19th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. trait TypeId {
  2.     fn get_typeid() -> usize;
  3. }
  4.  
  5. impl TypeId for i32 {
  6.     fn get_typeid() -> usize {return 1;}
  7. }
  8.  
  9. impl TypeId for String {
  10.     fn get_typeid() -> usize {return 2;}
  11. }
  12.  
  13. fn is_string<T: ?Sized + TypeId>(_t: &T) -> bool {
  14.     T::get_typeid() == String::get_typeid()
  15. }
  16.  
  17. fn main() {
  18.     assert_eq!(is_string(&0), false);
  19.     assert_eq!(is_string(&"cookie monster".to_string()), true);
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top