Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::any::TypeId;
- fn is_same<T, U>() -> bool
- where
- T: 'static,
- U: 'static
- {
- TypeId::of::<T>() == TypeId::of::<U>()
- }
- type Int = i32;
- fn test_by_param<T>(_value: T, expected: bool)
- where
- T: 'static
- {
- assert_eq!(is_same::<i8, T>(), expected);
- }
- fn main() {
- assert!(is_same::<i32, i32>());
- assert!(!is_same::<i32, f64>());
- assert!(is_same::<i32, Int>());
- assert!(!is_same::<u8, Int>());
- test_by_param(55i8, true);
- test_by_param([5, 2, 3], false);
- println!("All tests passed");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement