mvniekerk / tokio-cron-scheduler

Schedule tasks on Tokio using cron-like annotation
Apache License 2.0
529 stars 59 forks source link

sample on crates.io has a borrow error. #9

Closed davehorner closed 2 years ago

davehorner commented 2 years ago

https://crates.io/crates/tokio-cron-scheduler I copied and pasted the code from the webpage. When I build I get:

error[E0382]: borrow of moved value: `jj`
  --> src\main.rs:33:5
   |
28 |       let mut jj = Job::new_repeated(Duration::from_secs(8), |_uuid, _l| {
   |           ------ move occurs because `jj` has type `Job`, which does not implement the `Copy` trait
...
31 |       sched.add(jj);
   |                 -- value moved here
32 |
33 | /     jj.on_start_notification_add(Box::new(|job_id, notification_id, type_of_notification| {
34 | |       Box::pin(async move {
35 | |         println!("Job {:?} was started, notification {:?} ran ({:?})", job_id, notification_id, type_of_notification);
36 | |       })
37 | |     }));
   | |_______^ value borrowed here after move

if I jj.clone() that compiles; but it isn't right. I don't need that to work for my purposes, but I wanted to report it and learn something new if there's a solution.

thanks. --dave

mvniekerk commented 2 years ago

Hi @davehorner Thank you for the bug report. I've updated the README accordingly. Kindly check if this works for you?