Guest User

Untitled

a guest
Jul 17th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. trait MyTrait {
  2. fn my_fnc(&self);
  3. }
  4.  
  5. struct Service {
  6. x: String
  7. }
  8.  
  9. impl Drop for Service {
  10. fn drop(&mut self) {
  11. println!("Drop service");
  12. }
  13. }
  14.  
  15. struct Iface<'a> {
  16. service: &'a Service,
  17. }
  18.  
  19. impl<'a> MyTrait for Iface<'a> {
  20. fn my_fnc(&self) {
  21. println!("my_fnc");
  22. }
  23. }
  24.  
  25. fn main() {
  26. let service = Service{x: "".to_string()};
  27. let iface = Iface{service: &service};
  28.  
  29. launch_thread(iface);
  30.  
  31. println!("End main");
  32. }
  33.  
  34. fn launch_thread<'a>(iface: Iface<'a>) {
  35. std::thread::spawn(move || iface.my_fnc());
  36. }
Add Comment
Please, Sign In to add comment