Advertisement
Guest User

Untitled

a guest
May 20th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. use std::sync::Arc;
  2.  
  3. fn main() {
  4. let mut v: Vec<Arc<dyn Human>> = Vec::new();
  5. let me = Taiwanese::new();
  6. // works with a temporarary variable.
  7. let me_2 = Arc::clone(&me);
  8. v.push(me_2);
  9. v.push(Arc::clone(&me)); // type mismatch without temporary variable, why?
  10. v.push(me);
  11. }
  12.  
  13. trait Human {}
  14.  
  15. struct Taiwanese {}
  16.  
  17. impl Taiwanese {
  18. fn new() -> Arc<Taiwanese> {
  19. Arc::new(Taiwanese {})
  20. }
  21. }
  22.  
  23. impl Human for Taiwanese {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement