ruma-bot

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

debug.rs (1566B)


      1 use std::fmt;
      2 
      3 use crate::{Bot, BotBuilder, HandlerFnMap, MsgContent, State};
      4 
      5 struct Placeholder;
      6 
      7 impl fmt::Debug for Placeholder {
      8     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
      9         f.write_str("[...]")
     10     }
     11 }
     12 
     13 struct HandlerFnMapDbg<'a>(&'a HandlerFnMap);
     14 
     15 impl<'a> fmt::Debug for HandlerFnMapDbg<'a> {
     16     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     17         f.debug_map()
     18             .entries(self.0.iter().map(|(k, _)| (k, Placeholder)))
     19             .finish()
     20     }
     21 }
     22 
     23 impl fmt::Debug for BotBuilder {
     24     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     25         f.debug_struct("BotBuilder")
     26             .field("handlers", &HandlerFnMapDbg(&self.handlers))
     27             .field("homeserver_url", &self.homeserver_url)
     28             .field("username", &self.username)
     29             .field("password", &Placeholder)
     30             .finish()
     31     }
     32 }
     33 
     34 impl fmt::Debug for Bot {
     35     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     36         f.debug_struct("Bot")
     37             .field("client", &self.client)
     38             .field("handlers", &HandlerFnMapDbg(&self.handlers))
     39             .field("state", &self.state)
     40             .field("connection_details", &self.connection_details)
     41             .finish()
     42     }
     43 }
     44 
     45 impl<T> fmt::Debug for State<T>
     46 where
     47     T: fmt::Debug + Send + Sync,
     48 {
     49     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     50         write!(f, "{:?}", self.0)
     51     }
     52 }
     53 
     54 impl fmt::Debug for MsgContent {
     55     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     56         write!(f, "{:?}", self.0)
     57     }
     58 }