Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::any::Any;
- pub fn dedup_types(list: &mut Vec<Box<Any>>) {
- list.sort_unstable_by_key(|elem| elem.type_id());
- list.dedup_by_key(|elem| (*elem).type_id());
- }
- struct Alpha;
- struct Beta;
- struct Gamma;
- pub fn main() {
- let mut list = vec![
- Box::new(Alpha) as Box<Any>,
- Box::new(Gamma) as Box<Any>,
- Box::new(Alpha) as Box<Any>,
- Box::new(Beta) as Box<Any>,
- Box::new(Gamma) as Box<Any>,
- Box::new(Gamma) as Box<Any>,
- ];
- dedup_types(&mut list);
- assert_eq!(list.len(), 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement