diff options
| author | acdenisSK <[email protected]> | 2017-07-10 21:47:00 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-10 21:47:00 +0200 |
| commit | 710fa02405d8d740c4ee952822d856af0e845aa8 (patch) | |
| tree | 586c1ccb096e2d8f0b2916f566ec63fcbcc7cf16 /src/model/guild/guild_id.rs | |
| parent | Fixed clippy warnings (#120) (diff) | |
| download | serenity-710fa02405d8d740c4ee952822d856af0e845aa8.tar.xz serenity-710fa02405d8d740c4ee952822d856af0e845aa8.zip | |
Use a trait way of overloading the `ban` function instead of an enum
Possibly removes some overhead introduced by enums but makes the underlaying code of the function easier to read and is more concise
Diffstat (limited to 'src/model/guild/guild_id.rs')
| -rw-r--r-- | src/model/guild/guild_id.rs | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index 68212c7..c2cfc3d 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -46,30 +46,14 @@ impl GuildId { /// [`Guild::ban`]: struct.Guild.html#method.ban /// [`User`]: struct.User.html /// [Ban Members]: permissions/constant.BAN_MEMBERS.html - pub fn ban<U: Into<UserId>, BO: Into<BanOptions>>(&self, user: U, ban_options: BO) + pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, ban_options: BO) -> Result<()> { - - use self::BanOptions::*; - - match ban_options.into() { - DeleteMessageDays(dmd) => { - if dmd > 7 { - return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd))); - } - - http::ban_user(self.0, user.into().0, dmd, "") - }, - DMDReason(dmd, reason) => { - if dmd > 7 { - return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd))); - } - - http::ban_user(self.0, user.into().0, dmd, &*reason) - }, - Reason(reason) => { - http::ban_user(self.0, user.into().0, 0, &*reason) - }, + let dmd = ban_options.dmd(); + if dmd > 7 { + return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd))); } + + http::ban_user(self.0, user.into().0, dmd, &*ban_options.reason()) } /// Gets a list of the guild's bans. |