Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.55 KB | None | 0 0
  1. pub struct Watcher{
  2.     dir: String,
  3.     rules: Vec<Rule>,
  4.     handle: Option<thread::JoinHandle<()>>,
  5.     running: bool
  6. }
  7.  
  8. impl Watcher{
  9.     fn start(&mut self){
  10.         self.running = true;
  11.  
  12.         let cself = Arc::new(self);
  13.         let t = thread::spawn(move || {
  14.             loop{
  15.                 if cself.running == false{
  16.                     break
  17.                 }
  18.                 println!("Ama tread");
  19.                 thread::sleep(Duration::from_secs(2));
  20.  
  21.             }
  22.  
  23.         });
  24.         self.handle = Some(t);
  25.     }
  26.  
  27. }
  28.  
  29.  
  30.  
  31.  
  32. ERRORS:
  33. error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
  34.   --> src/watch.rs:35:30
  35.    |
  36. 35 |         let cself = Arc::new(self);
  37.    |                              ^^^^
  38.    |
  39. note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 32:5...
  40.   --> src/watch.rs:32:5
  41.    |
  42. 32 | /     fn start(&mut self){
  43. 33 | |         self.running = true;
  44. 34 | |
  45. 35 | |         let cself = Arc::new(self);
  46. ...  |
  47. 47 | |         self.handle = Some(t);
  48. 48 | |     }
  49.    | |_____^
  50.    = note: ...so that the expression is assignable:
  51.            expected &mut watch::Watcher
  52.               found &mut watch::Watcher
  53.    = note: but, the lifetime must be valid for the static lifetime...
  54. note: ...so that the type `[closure@src/watch.rs:36:31: 46:10 cself:std::sync::Arc<&mut watch::Watcher>]` will meet its required lifetime bounds
  55.   --> src/watch.rs:36:17
  56.    |
  57. 36 |         let t = thread::spawn(move || {
  58.    |                 ^^^^^^^^^^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement