Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. use std::thread;
  2. use std::time::Duration;
  3.  
  4. struct Example {
  5. prop: String,
  6. }
  7.  
  8. impl Example {
  9. fn run(self: &Self) -> String {
  10. return self.prop;
  11. }
  12.  
  13. }
  14.  
  15. fn main() {
  16. let mut examples: Vec<&Example> = vec![];
  17.  
  18. let example = Example { prop: "hello".to_string() };
  19.  
  20. examples.push(&example);
  21.  
  22.  
  23. loop {
  24. start_loop(&mut examples);
  25. }
  26. unreachable!();
  27. }
  28.  
  29. fn start_loop(examples: &'static mut Vec<&Example>) {
  30. // loop {
  31. for example in examples {
  32. example.prop = "world".to_string();
  33. thread::spawn(move || {
  34. example.run();
  35. });
  36. }
  37. thread::sleep(Duration::from_millis(1));
  38. // }
  39. // unreachable!();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement