Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. trait TR {
  2. fn fn1(&self);
  3. }
  4.  
  5. struct S {}
  6.  
  7. impl TR for S {
  8. fn fn1(&self) {
  9. dbg!("fn1");
  10. }
  11. }
  12.  
  13. struct SWrap {
  14. t: Box<dyn TR>
  15. }
  16.  
  17. impl SWrap {
  18. fn fn1(&self) {
  19. self.t.fn1();
  20. }
  21. }
  22.  
  23. fn wrap<T: TR + 'static>(t: T) -> SWrap {
  24. SWrap{t:Box::new(t)}
  25. }
  26.  
  27. fn main() {
  28. let s = S{};
  29. let sw = wrap(s);
  30. let t = sw.t;
  31. std::thread::spawn(move || {
  32. t.fn1();
  33. });
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement