Guest User

Untitled

a guest
Jul 21st, 2019
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::any::TypeId;
  2.  
  3. fn is_same<T, U>() -> bool
  4. where
  5. T: 'static,
  6. U: 'static
  7. {
  8. TypeId::of::<T>() == TypeId::of::<U>()
  9. }
  10.  
  11. type Int = i32;
  12.  
  13. fn test_by_param<T>(_value: T, expected: bool)
  14. where
  15. T: 'static
  16. {
  17. assert_eq!(is_same::<i8, T>(), expected);
  18. }
  19.  
  20. fn main() {
  21. assert!(is_same::<i32, i32>());
  22. assert!(!is_same::<i32, f64>());
  23. assert!(is_same::<i32, Int>());
  24. assert!(!is_same::<u8, Int>());
  25.  
  26. test_by_param(55i8, true);
  27. test_by_param([5, 2, 3], false);
  28.  
  29. println!("All tests passed");
  30. }
RAW Paste Data