Advertisement
Guest User

Untitled

a guest
May 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 3.57 KB | None | 0 0
  1. fn on_update(&mut self, update: &Update, api: &Api)
  2.     {
  3.         if let UpdateKind::Message(ref message) = update.kind
  4.         {
  5.             if let MessageKind::Text {ref data, ..} = message.kind
  6.             {
  7.                 println!("<{}>: {}", &message.from.first_name, data);
  8.                 {
  9.                     match super::trim_command(self, data)
  10.                     {
  11.                         Some(trimmed) => {
  12.                             let mut splitted = trimmed.split(' ');
  13.                             let (time, message_text) = (splitted.next().unwrap(), splitted.next().unwrap());
  14.                             let mut ctx = Context::new();
  15.                             ctx.var("m", 60.0);
  16.                             ctx.var("h", 3600.0);
  17.                             match eval_str_with_context(time, ctx)
  18.                             {
  19.                                 Ok(res) => {
  20.                                     let time_delay = Delay::new(Instant::now().add(Duration::from_secs(res as u64))).from_err();
  21.                                     let alert_api = api.clone();
  22.                                     let lol = api.send(message.text_reply("you will be reminded"))
  23.                                         .join(time_delay)
  24.                                         .map_err(|_| ())
  25.                                         .and_then(move |(message, _)| {
  26.                                             alert_api.send(message.text_reply(message_text));
  27.                                             Ok(())
  28.                                         });
  29.                                     tokio::executor::current_thread::spawn(lol);
  30.                                 }
  31.                                 Err(error) => api.spawn(message.text_reply("time parsing error"))
  32.                             }
  33.                         }
  34.                         None => {
  35.                             api.spawn(message.text_reply("please provide arguments"))
  36.                         }
  37.                     }
  38.                 };
  39.             }
  40.         }
  41.  
  42.  
  43.  
  44.  
  45.  
  46. error[E0495]: cannot infer an appropriate lifetime for pattern due to conflicting requirements
  47.   --> src/handlers/alert.rs:43:36
  48.    |
  49. 43 |         if let UpdateKind::Message(ref message) = update.kind
  50.    |                                    ^^^^^^^^^^^
  51.    |
  52. note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the method body at 41:5...
  53.   --> src/handlers/alert.rs:41:5
  54.    |
  55. 41 | /     fn on_update(&mut self, update: &Update, api: &Api)
  56. 42 | |     {
  57. 43 | |         if let UpdateKind::Message(ref message) = update.kind
  58. 44 | |         {
  59. ...  |
  60. 80 | |         }
  61. 81 | |     }
  62.    | |_____^
  63. note: ...so that reference does not outlive borrowed content
  64.   --> src/handlers/alert.rs:43:36
  65.    |
  66. 43 |         if let UpdateKind::Message(ref message) = update.kind
  67.    |                                    ^^^^^^^^^^^
  68.    = note: but, the lifetime must be valid for the static lifetime...
  69. note: ...so that the type `futures::AndThen<futures::MapErr<futures::Join<telegram_bot_fork::TelegramFuture<telegram_bot_fork::Message>, futures::future::FromErr<tokio_timer::Delay, telegram_bot_fork::Error>>, [closure@src/handlers/alert.rs:64:50: 64:56]>, std::result::Result<(), ()>, [closure@src/handlers/alert.rs:65:51: 68:42 alert_api:telegram_bot_fork::Api, message_text:&str]>` will meet its required lifetime bounds
  70.   --> src/handlers/alert.rs:69:37
  71.    |
  72. 69 |                                     tokio::executor::current_thread::spawn(lol);
  73.    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement