Advertisement
Guest User

Untitled

a guest
Jan 15th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.94 KB | None | 0 0
  1. struct Command {
  2.     pin: u8,
  3.     time_of_creation: DateTime<Local>,
  4.     timer: i64,
  5.     status: u8
  6. }
  7.  
  8.  
  9.  
  10. impl Command {
  11.     pub fn new(val: Value) -> Command {
  12.         Command{
  13.             pin: val["pin"].as_u64().unwrap_or(0) as u8,
  14.             time_of_creation: Local::now(),
  15.             timer: val["timer"].as_i64().unwrap_or(0),
  16.             status: val["status"].as_u64().unwrap_or(0) as u8
  17.         }
  18.     }
  19.  
  20.     fn ready_to_execute(&self, sender: &Sender<(u8, u8)>) -> bool{
  21.         let current_time: DateTime<Local> = Local::now();
  22.         let timer = self.time_of_creation + Duration::seconds(self.timer);
  23.         if timer <= current_time {
  24.             match sender.send((self.pin, self.status)){
  25.                 Ok(b) => (),
  26.                 Err(b) => println!("Error {}, timer: {}, time of creation {}", b, timer, self.time_of_creation)
  27.             }
  28.             true
  29.         } else {
  30.             false
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement