Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait TypeId {
- fn get_typeid() -> usize;
- }
- impl TypeId for i32 {
- fn get_typeid() -> usize {return 1;}
- }
- impl TypeId for String {
- fn get_typeid() -> usize {return 2;}
- }
- fn is_string<T: ?Sized + TypeId>(_t: &T) -> bool {
- T::get_typeid() == String::get_typeid()
- }
- fn main() {
- assert_eq!(is_string(&0), false);
- assert_eq!(is_string(&"cookie monster".to_string()), true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement