serenity/framework/standard/structures/
check.rs1use std::error::Error;
2use std::fmt;
3
4use futures::future::BoxFuture;
5
6use crate::client::Context;
7use crate::framework::standard::{Args, CommandOptions};
8use crate::model::channel::Message;
9
10#[derive(Clone, Debug)]
16#[non_exhaustive]
17pub enum Reason {
18 Unknown,
20 User(String),
22 Log(String),
24 UserAndLog { user: String, log: String },
26}
27
28impl Error for Reason {}
29
30pub type CheckFunction = for<'fut> fn(
31 &'fut Context,
32 &'fut Message,
33 &'fut mut Args,
34 &'fut CommandOptions,
35) -> BoxFuture<'fut, Result<(), Reason>>;
36
37pub struct Check {
42 pub name: &'static str,
44 pub function: CheckFunction,
46 pub check_in_help: bool,
49 pub display_in_help: bool,
52}
53
54impl fmt::Debug for Check {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 f.debug_struct("Check")
57 .field("name", &self.name)
58 .field("function", &"<fn>")
59 .field("check_in_help", &self.check_in_help)
60 .field("display_in_help", &self.display_in_help)
61 .finish()
62 }
63}
64
65impl fmt::Display for Reason {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 match self {
68 Self::Unknown => f.write_str("Unknown"),
69 Self::User(reason) => write!(f, "User {reason}"),
70 Self::Log(reason) => write!(f, "Log {reason}"),
71 Self::UserAndLog {
72 user,
73 log,
74 } => {
75 write!(f, "UserAndLog {{user: {user}, log: {log}}}")
76 },
77 }
78 }
79}
80
81impl PartialEq for Check {
82 fn eq(&self, other: &Self) -> bool {
83 self.name == other.name
84 }
85}