SHARE
TWEET

Untitled

a guest Jun 20th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::any::Any;
  2.  
  3. pub fn dedup_types(list: &mut Vec<Box<Any>>)  {
  4.     list.sort_unstable_by_key(|elem| elem.type_id());
  5.     list.dedup_by_key(|elem| (*elem).type_id());
  6. }
  7.  
  8. struct Alpha;
  9. struct Beta;
  10. struct Gamma;
  11.  
  12. pub fn main() {
  13.     let mut list = vec![
  14.         Box::new(Alpha) as Box<Any>,
  15.         Box::new(Gamma) as Box<Any>,
  16.         Box::new(Alpha) as Box<Any>,
  17.         Box::new(Beta) as Box<Any>,
  18.         Box::new(Gamma) as Box<Any>,
  19.         Box::new(Gamma) as Box<Any>,
  20.     ];
  21.    
  22.     dedup_types(&mut list);
  23.     assert_eq!(list.len(), 3);
  24. }
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