Skip to content

Commit

Permalink
Add Debug derives to more public types
Browse files Browse the repository at this point in the history
  • Loading branch information
thelearnerofcode committed Nov 7, 2017
1 parent 05dad71 commit e5a6f3a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/framework/standard/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub type AfterHook = Fn(&mut Context, &Message, &str, Result<(), Error>) + Send
pub(crate) type InternalCommand = Arc<Command>;
pub type PrefixCheck = Fn(&mut Context, &Message) -> Option<String> + Send + Sync + 'static;

#[derive(Debug)]
pub enum CommandOrAlias {
Alias(String),
Command(InternalCommand),
Expand All @@ -41,6 +42,7 @@ pub enum CommandType {
WithCommands(Help),
}

#[derive(Debug)]
pub struct CommandGroup {
pub prefix: Option<String>,
pub commands: HashMap<String, CommandOrAlias>,
Expand Down Expand Up @@ -98,6 +100,25 @@ impl Command {
}
}

impl fmt::Debug for Command {
// TODO: add Command::checks somehow?
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("Command")
.field("bucket", &self.bucket)
.field("desc", &self.desc)
.field("example", &self.example)
.field("usage", &self.usage)
.field("min_args", &self.min_args)
.field("required_permissions", &self.required_permissions)
.field("allowed_roles", &self.allowed_roles)
.field("help_available", &self.help_available)
.field("dm_only", &self.dm_only)
.field("guild_only", &self.guild_only)
.field("owners_only", &self.owners_only)
.finish()
}
}

impl Default for Command {
fn default() -> Command {
Command {
Expand Down
1 change: 1 addition & 0 deletions src/framework/standard/create_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::Arc;
use client::Context;
use model::{Message, Permissions};

#[derive(Debug)]
pub struct CreateCommand(pub Command);

impl CreateCommand {
Expand Down
1 change: 1 addition & 0 deletions src/internal/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use chrono::{DateTime, Duration, Utc};
use std::thread;
use std::time::Duration as StdDuration;

#[derive(Debug)]
pub struct Timer {
due: DateTime<Utc>,
duration: Duration,
Expand Down
2 changes: 2 additions & 0 deletions src/model/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub fn user_has_perms(channel_id: ChannelId, mut permissions: Permissions) -> Re
Ok(permissions.is_empty())
}

#[derive(Debug)]
pub struct U16Visitor;

impl<'de> Visitor<'de> for U16Visitor {
Expand Down Expand Up @@ -216,6 +217,7 @@ impl<'de> Visitor<'de> for U16Visitor {
fn visit_u64<E: DeError>(self, v: u64) -> StdResult<Self::Value, E> { Ok(v as u16) }
}

#[derive(Debug)]
pub struct U64Visitor;

impl<'de> Visitor<'de> for U64Visitor {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/message_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ pub enum ContentModifier {
}

/// Describes formatting on string content
#[derive(Default, Clone)]
#[derive(Debug, Default, Clone)]
pub struct Content {
pub italic: bool,
pub bold: bool,
Expand Down Expand Up @@ -912,15 +912,15 @@ impl From<ContentModifier> for Content {
mod private {
use super::{Content, ContentModifier};
use std::fmt;

pub trait A {}

impl A for ContentModifier {}
impl A for Content {}
impl<T: fmt::Display> A for T {}
}


/// This trait only exists as way to bypass the shouting of the compiler. Specifically "conflicting
/// implementations in core" and alike.
/// However is not meant to be used outside.
Expand All @@ -940,7 +940,7 @@ impl<T: fmt::Display> I for T {
}
}
}

impl I for ContentModifier {
fn into(self) -> Content { self.to_content() }
}
Expand Down

0 comments on commit e5a6f3a

Please sign in to comment.