Skip to content

Commit

Permalink
Implement the Display and Error traits for the check Reason (#1102
Browse files Browse the repository at this point in the history
)
  • Loading branch information
peppizza committed Dec 2, 2020
1 parent 0de77e7 commit 2c9c64f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/framework/standard/structures/check.rs
@@ -1,9 +1,9 @@
use std::fmt::Debug;
use std::fmt;
use crate::model::channel::Message;
use crate::client::Context;
use crate::framework::standard::{Args, CommandOptions};
use crate::model::channel::Message;
use futures::future::BoxFuture;
use std::error::Error;
use std::fmt::{self, Debug, Display};

/// This type describes why a check has failed.
///
Expand All @@ -27,6 +27,8 @@ pub enum Reason {
UserAndLog { user: String, log: String },
}

impl Error for Reason {}

pub type CheckFunction = for<'fut> fn(
&'fut Context,
&'fut Message,
Expand Down Expand Up @@ -63,6 +65,19 @@ impl Debug for Check {
}
}

impl Display for Reason {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Unknown => write!(f, "Unknown"),
Self::User(reason) => write!(f, "User {}", reason),
Self::Log(reason) => write!(f, "Log {}", reason),
Self::UserAndLog { user, log } => {
write!(f, "UserAndLog {{user: {}, log: {}}}", user, log)
}
}
}
}

impl PartialEq for Check {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
Expand Down

0 comments on commit 2c9c64f

Please sign in to comment.