ruma-bot

git clone git://archive.git.mtrnord.blog/MTRNord/ruma-bot.git
Log | Files | Refs

util.rs (897B)


      1 // This module is not public, and all exports from it are #[doc(hidden)], so the docs wouldn't be
      2 // visible anyway.
      3 #![allow(missing_docs)]
      4 
      5 use crate::{Bot, MsgContent, State};
      6 
      7 #[derive(Debug)]
      8 pub struct HandlerParamMatcher<'a> {
      9     pub bot: &'a Bot,
     10     pub msg_content: &'a str,
     11 }
     12 
     13 pub trait GetParam<T> {
     14     fn get(&self) -> Option<T>;
     15 }
     16 
     17 impl GetParam<Bot> for HandlerParamMatcher<'_> {
     18     fn get(&self) -> Option<Bot> {
     19         Some(self.bot.clone())
     20     }
     21 }
     22 
     23 // TODO: There should be a way of replacing 'static with 'a here without getting an error
     24 impl<T: Clone + Send + Sync + 'static> GetParam<State<T>> for HandlerParamMatcher<'_> {
     25     fn get(&self) -> Option<State<T>> {
     26         self.bot.state.get().cloned()
     27     }
     28 }
     29 
     30 impl GetParam<MsgContent> for HandlerParamMatcher<'_> {
     31     fn get(&self) -> Option<MsgContent> {
     32         Some(MsgContent(self.msg_content.to_owned()))
     33     }
     34 }