aboutsummaryrefslogtreecommitdiff
path: root/src/model/guild
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-07-27 06:42:48 +0200
committeracdenisSK <[email protected]>2017-07-27 07:30:23 +0200
commit550030264952f0e0043b63f4582bb817ef8bbf37 (patch)
treeb921e2f78fd603a5ca671623083a32806fd16090 /src/model/guild
parentUse a consistent indentation style (diff)
downloadserenity-550030264952f0e0043b63f4582bb817ef8bbf37.tar.xz
serenity-550030264952f0e0043b63f4582bb817ef8bbf37.zip
rustfmt
Diffstat (limited to 'src/model/guild')
-rw-r--r--src/model/guild/audit_log.rs168
-rw-r--r--src/model/guild/emoji.rs42
-rw-r--r--src/model/guild/feature.rs6
-rw-r--r--src/model/guild/guild_id.rs153
-rw-r--r--src/model/guild/integration.rs6
-rw-r--r--src/model/guild/member.rs136
-rw-r--r--src/model/guild/mod.rs253
-rw-r--r--src/model/guild/partial_guild.rs112
-rw-r--r--src/model/guild/role.rs72
9 files changed, 430 insertions, 518 deletions
diff --git a/src/model/guild/audit_log.rs b/src/model/guild/audit_log.rs
index a5097b2..020ad77 100644
--- a/src/model/guild/audit_log.rs
+++ b/src/model/guild/audit_log.rs
@@ -1,5 +1,5 @@
-use super::super::{UserId, AuditLogEntryId};
-use serde::de::{self, Deserialize, Deserializer, Visitor, MapAccess};
+use super::super::{AuditLogEntryId, UserId};
+use serde::de::{self, Deserialize, Deserializer, MapAccess, Visitor};
use std::fmt;
use std::collections::HashMap;
@@ -45,11 +45,11 @@ pub enum Action {
#[derive(Deserialize)]
pub struct Change {
- #[serde(rename="key")]
+ #[serde(rename = "key")]
pub name: String,
- #[serde(rename="old_value")]
+ #[serde(rename = "old_value")]
pub old: String,
- #[serde(rename="new_value")]
+ #[serde(rename = "new_value")]
pub new: String,
}
@@ -62,12 +62,12 @@ pub struct AuditLogEntry {
/// Determines to what entity an [`action`] was used on.
///
/// [`action`]: #structfield.action
- #[serde(deserialize_with="deserialize_target", rename="target_type")]
+ #[serde(deserialize_with = "deserialize_target", rename = "target_type")]
pub target: Target,
/// Determines what action was done on a [`target`]
///
/// [`target`]: #structfield.target
- #[serde(deserialize_with="deserialize_action", rename="action_type")]
+ #[serde(deserialize_with = "deserialize_action", rename = "action_type")]
pub action: Action,
/// What was the reasoning by doing an action on a target? If there was one.
pub reason: Option<String>,
@@ -77,7 +77,6 @@ pub struct AuditLogEntry {
pub changes: Vec<Change>,
/// The id of this entry.
pub id: AuditLogEntryId,
-
}
fn deserialize_target<'de, D: Deserializer<'de>>(de: D) -> Result<Target, D::Error> {
@@ -92,22 +91,22 @@ fn deserialize_target<'de, D: Deserializer<'de>>(de: D) -> Result<Target, D::Err
fn visit_i32<E: de::Error>(self, value: i32) -> Result<Target, E> {
Ok(if value < 10 {
- Target::Guild
- } else if value < 20 {
- Target::Channel
- } else if value < 30 {
- Target::User
- } else if value < 40 {
- Target::Role
- } else if value < 50 {
- Target::Invite
- } else if value < 60 {
- Target::Webhook
- } else if value < 70 {
- Target::Emoji
- } else {
- return Err(E::custom(format!("Unexpected target number: {}", value)));
- })
+ Target::Guild
+ } else if value < 20 {
+ Target::Channel
+ } else if value < 30 {
+ Target::User
+ } else if value < 40 {
+ Target::Role
+ } else if value < 50 {
+ Target::Invite
+ } else if value < 60 {
+ Target::Webhook
+ } else if value < 70 {
+ Target::Emoji
+ } else {
+ return Err(E::custom(format!("Unexpected target number: {}", value)));
+ })
}
}
@@ -127,58 +126,58 @@ fn deserialize_action<'de, D: Deserializer<'de>>(de: D) -> Result<Action, D::Err
fn visit_i32<E: de::Error>(self, value: i32) -> Result<Action, E> {
// todo: improve this
Ok(if value == 1 {
- Action::GuildUpdate
- } else if value == 10 {
- Action::ChannelCreate
- } else if value == 11 {
- Action::ChannelUpdate
- } else if value == 12 {
- Action::ChannelDelete
- } else if value == 13 {
- Action::ChannelOverwriteCreate
- } else if value == 14 {
- Action::ChannelOverwriteUpdate
- } else if value == 15 {
- Action::ChannelOverwriteDelete
- } else if value == 20 {
- Action::MemberKick
- } else if value == 21 {
- Action::MemberPrune
- } else if value == 22 {
- Action::MemberBanAdd
- } else if value == 23 {
- Action::MemberBanRemove
- } else if value == 24 {
- Action::MemberUpdate
- } else if value == 25 {
- Action::MemberRoleUpdate
- } else if value == 30 {
- Action::RoleCreate
- } else if value == 31 {
- Action::RoleUpdate
- } else if value == 32 {
- Action::RoleDelete
- } else if value == 40 {
- Action::InviteCreate
- } else if value == 41 {
- Action::InviteUpdate
- } else if value == 42 {
- Action::InviteDelete
- } else if value == 50 {
- Action::WebhookCreate
- } else if value == 51 {
- Action::WebhookUpdate
- } else if value == 52 {
- Action::WebhookDelete
- } else if value == 60 {
- Action::EmojiCreate
- } else if value == 61 {
- Action::EmojiUpdate
- } else if value == 62 {
- Action::EmojiDelete
- } else {
- return Err(E::custom(format!("Unexpected action number: {}", value)));
- })
+ Action::GuildUpdate
+ } else if value == 10 {
+ Action::ChannelCreate
+ } else if value == 11 {
+ Action::ChannelUpdate
+ } else if value == 12 {
+ Action::ChannelDelete
+ } else if value == 13 {
+ Action::ChannelOverwriteCreate
+ } else if value == 14 {
+ Action::ChannelOverwriteUpdate
+ } else if value == 15 {
+ Action::ChannelOverwriteDelete
+ } else if value == 20 {
+ Action::MemberKick
+ } else if value == 21 {
+ Action::MemberPrune
+ } else if value == 22 {
+ Action::MemberBanAdd
+ } else if value == 23 {
+ Action::MemberBanRemove
+ } else if value == 24 {
+ Action::MemberUpdate
+ } else if value == 25 {
+ Action::MemberRoleUpdate
+ } else if value == 30 {
+ Action::RoleCreate
+ } else if value == 31 {
+ Action::RoleUpdate
+ } else if value == 32 {
+ Action::RoleDelete
+ } else if value == 40 {
+ Action::InviteCreate
+ } else if value == 41 {
+ Action::InviteUpdate
+ } else if value == 42 {
+ Action::InviteDelete
+ } else if value == 50 {
+ Action::WebhookCreate
+ } else if value == 51 {
+ Action::WebhookUpdate
+ } else if value == 52 {
+ Action::WebhookDelete
+ } else if value == 60 {
+ Action::EmojiCreate
+ } else if value == 61 {
+ Action::EmojiUpdate
+ } else if value == 62 {
+ Action::EmojiDelete
+ } else {
+ return Err(E::custom(format!("Unexpected action number: {}", value)));
+ })
}
}
@@ -190,12 +189,12 @@ impl<'de> Deserialize<'de> for AuditLogs {
#[derive(Deserialize)]
#[serde(field_identifier)]
enum Field {
- #[serde(rename="audit_log_entries")]
- AuditLogEntries
+ #[serde(rename = "audit_log_entries")]
+ AuditLogEntries,
}
struct EntriesVisitor;
-
+
impl<'de> Visitor<'de> for EntriesVisitor {
type Value = AuditLogs;
@@ -209,16 +208,21 @@ impl<'de> Deserialize<'de> for AuditLogs {
match key {
Field::AuditLogEntries => {
break map.next_value::<Vec<AuditLogEntry>>()?;
- }
+ },
}
}
};
- Ok(AuditLogs { entries: audit_log_entries.into_iter().map(|entry| (entry.id, entry)).collect() })
+ Ok(AuditLogs {
+ entries: audit_log_entries
+ .into_iter()
+ .map(|entry| (entry.id, entry))
+ .collect(),
+ })
}
}
const FIELD: &'static [&'static str] = &["audit_log_entries"];
de.deserialize_struct("AuditLogs", FIELD, EntriesVisitor)
}
-} \ No newline at end of file
+}
diff --git a/src/model/guild/emoji.rs b/src/model/guild/emoji.rs
index 9a8ad39..3893f52 100644
--- a/src/model/guild/emoji.rs
+++ b/src/model/guild/emoji.rs
@@ -1,17 +1,17 @@
use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite};
use super::super::{EmojiId, RoleId};
-#[cfg(feature="cache")]
+#[cfg(feature = "cache")]
use std::mem;
-#[cfg(all(feature="cache", feature="model"))]
+#[cfg(all(feature = "cache", feature = "model"))]
use super::super::ModelError;
-#[cfg(feature="cache")]
-use ::CACHE;
-#[cfg(feature="cache")]
-use ::internal::prelude::*;
-#[cfg(all(feature="cache", feature="model"))]
-use ::http;
-#[cfg(feature="cache")]
+#[cfg(feature = "cache")]
+use CACHE;
+#[cfg(feature = "cache")]
+use internal::prelude::*;
+#[cfg(all(feature = "cache", feature = "model"))]
+use http;
+#[cfg(feature = "cache")]
use super::super::GuildId;
/// Represents a custom guild emoji, which can either be created using the API,
@@ -38,7 +38,7 @@ pub struct Emoji {
pub roles: Vec<RoleId>,
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl Emoji {
/// Deletes the emoji.
///
@@ -69,7 +69,7 @@ impl Emoji {
/// Err(_) => println!("Could not delete emoji.")
/// }
/// ```
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn delete(&self) -> Result<()> {
match self.find_guild_id() {
Some(guild_id) => http::delete_emoji(guild_id.0, self.id.0),
@@ -104,7 +104,7 @@ impl Emoji {
/// let _ = emoji.edit("blobuwu");
/// assert_eq!(emoji.name, "blobuwu");
/// ```
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn edit(&mut self, name: &str) -> Result<()> {
match self.find_guild_id() {
Some(guild_id) => {
@@ -149,7 +149,7 @@ impl Emoji {
/// println!("{} is owned by {}", emoji.name, guild_id);
/// }
/// ```
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn find_guild_id(&self) -> Option<GuildId> {
for guild in CACHE.read().unwrap().guilds.values() {
let guild = guild.read().unwrap();
@@ -183,9 +183,7 @@ impl Emoji {
/// println!("Direct link to emoji image: {}", emoji.url());
/// ```
#[inline]
- pub fn url(&self) -> String {
- format!(cdn!("/emojis/{}.png"), self.id)
- }
+ pub fn url(&self) -> String { format!(cdn!("/emojis/{}.png"), self.id) }
}
impl Display for Emoji {
@@ -203,21 +201,15 @@ impl Display for Emoji {
}
impl Display for EmojiId {
- fn fmt(&self, f: &mut Formatter) -> FmtResult {
- Display::fmt(&self.0, f)
- }
+ fn fmt(&self, f: &mut Formatter) -> FmtResult { Display::fmt(&self.0, f) }
}
impl From<Emoji> for EmojiId {
/// Gets the Id of an `Emoji`.
- fn from(emoji: Emoji) -> EmojiId {
- emoji.id
- }
+ fn from(emoji: Emoji) -> EmojiId { emoji.id }
}
impl<'a> From<&'a Emoji> for EmojiId {
/// Gets the Id of an `Emoji`.
- fn from(emoji: &Emoji) -> EmojiId {
- emoji.id
- }
+ fn from(emoji: &Emoji) -> EmojiId { emoji.id }
}
diff --git a/src/model/guild/feature.rs b/src/model/guild/feature.rs
index cfbcabc..40fd3fd 100644
--- a/src/model/guild/feature.rs
+++ b/src/model/guild/feature.rs
@@ -9,17 +9,17 @@ pub enum Feature {
///
/// [`Guild`]: struct.Guild.html
/// [`Guild::splash`]: struct.Guild.html#structfield.splash
- #[serde(rename="INVITE_SPLASH")]
+ #[serde(rename = "INVITE_SPLASH")]
InviteSplash,
/// The [`Guild`] can set a Vanity URL, which is a custom-named permanent
/// invite code.
///
/// [`Guild`]: struct.Guild.html
- #[serde(rename="VANITY_URL")]
+ #[serde(rename = "VANITY_URL")]
VanityUrl,
/// The [`Guild`] has access to VIP voice channel regions.
///
/// [`Guild`]: struct.Guild.html
- #[serde(rename="VIP_REGIONS")]
+ #[serde(rename = "VIP_REGIONS")]
VipRegions,
}
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs
index 6fbaddf..a0b69d1 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -1,23 +1,21 @@
use std::fmt::{Display, Formatter, Result as FmtResult};
-use ::model::*;
-use ::model::guild::BanOptions;
-
-#[cfg(feature="cache")]
-use ::CACHE;
-#[cfg(feature="model")]
-use ::builder::{EditGuild, EditMember, EditRole};
-#[cfg(feature="model")]
-use ::http;
-#[cfg(feature="model")]
-use ::internal::prelude::*;
-
-#[cfg(feature="model")]
+use model::*;
+use model::guild::BanOptions;
+
+#[cfg(feature = "cache")]
+use CACHE;
+#[cfg(feature = "model")]
+use builder::{EditGuild, EditMember, EditRole};
+#[cfg(feature = "model")]
+use http;
+#[cfg(feature = "model")]
+use internal::prelude::*;
+
+#[cfg(feature = "model")]
impl GuildId {
/// Converts the guild Id into the default channel's Id.
#[inline]
- pub fn as_channel_id(&self) -> ChannelId {
- ChannelId(self.0)
- }
+ pub fn as_channel_id(&self) -> ChannelId { ChannelId(self.0) }
/// Ban a [`User`] from the guild. All messages by the
/// user within the last given number of days given will be deleted.
@@ -42,12 +40,12 @@ impl GuildId {
/// Returns a [`ModelError::DeleteMessageDaysAmount`] if the number of
/// days' worth of messages to delete is over the maximum.
///
- /// [`ModelError::DeleteMessageDaysAmount`]: enum.ModelError.html#variant.DeleteMessageDaysAmount
+ /// [`ModelError::DeleteMessageDaysAmount`]:
+ /// enum.ModelError.html#variant.DeleteMessageDaysAmount
/// [`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: BanOptions>(&self, user: U, ban_options: BO)
- -> Result<()> {
+ pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, ban_options: BO) -> Result<()> {
let dmd = ban_options.dmd();
if dmd > 7 {
return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd)));
@@ -68,15 +66,11 @@ impl GuildId {
///
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
#[inline]
- pub fn bans(&self) -> Result<Vec<Ban>> {
- http::get_bans(self.0)
- }
+ pub fn bans(&self) -> Result<Vec<Ban>> { http::get_bans(self.0) }
/// Gets a list of the guild's audit log entries
#[inline]
- pub fn audit_logs(&self) -> Result<AuditLogs> {
- http::get_audit_logs(self.0)
- }
+ pub fn audit_logs(&self) -> Result<AuditLogs> { http::get_audit_logs(self.0) }
/// Gets all of the guild's channels over the REST API.
///
@@ -150,8 +144,9 @@ impl GuildId {
/// Requires the [Manage Guild] permission.
///
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
- pub fn create_integration<I>(&self, integration_id: I, kind: &str)
- -> Result<()> where I: Into<IntegrationId> {
+ pub fn create_integration<I>(&self, integration_id: I, kind: &str) -> Result<()>
+ where
+ I: Into<IntegrationId>, {
let integration_id = integration_id.into();
let map = json!({
"id": integration_id.0,
@@ -183,9 +178,7 @@ impl GuildId {
///
/// [`Guild::delete`]: struct.Guild.html#method.delete
#[inline]
- pub fn delete(&self) -> Result<PartialGuild> {
- http::delete_guild(self.0)
- }
+ pub fn delete(&self) -> Result<PartialGuild> { http::delete_guild(self.0) }
/// Deletes an [`Emoji`] from the guild.
///
@@ -270,7 +263,9 @@ impl GuildId {
/// ```
#[inline]
pub fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()>
- where F: FnOnce(EditMember) -> EditMember, U: Into<UserId> {
+ where
+ F: FnOnce(EditMember) -> EditMember,
+ U: Into<UserId>, {
http::edit_member(self.0, user_id.into().0, &f(EditMember::default()).0)
}
@@ -304,7 +299,9 @@ impl GuildId {
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
#[inline]
pub fn edit_role<F, R>(&self, role_id: R, f: F) -> Result<Role>
- where F: FnOnce(EditRole) -> EditRole, R: Into<RoleId> {
+ where
+ F: FnOnce(EditRole) -> EditRole,
+ R: Into<RoleId>, {
http::edit_role(self.0, role_id.into().0, &f(EditRole::default()).0)
}
@@ -324,32 +321,24 @@ impl GuildId {
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn emojis(&self) -> Result<Vec<Emoji>> {
- http::get_emojis(self.0)
- }
+ pub fn emojis(&self) -> Result<Vec<Emoji>> { http::get_emojis(self.0) }
/// Search the cache for the guild.
- #[cfg(feature="cache")]
- pub fn find(&self) -> Option<Arc<RwLock<Guild>>> {
- CACHE.read().unwrap().guild(*self)
- }
+ #[cfg(feature = "cache")]
+ pub fn find(&self) -> Option<Arc<RwLock<Guild>>> { CACHE.read().unwrap().guild(*self) }
/// Requests the guild over REST.
///
/// Note that this will not be a complete guild, as REST does not send
/// all data with a guild retrieval.
#[inline]
- pub fn get(&self) -> Result<PartialGuild> {
- http::get_guild(self.0)
- }
+ pub fn get(&self) -> Result<PartialGuild> { http::get_guild(self.0) }
/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
#[inline]
- pub fn integrations(&self) -> Result<Vec<Integration>> {
- http::get_guild_integrations(self.0)
- }
+ pub fn integrations(&self) -> Result<Vec<Integration>> { http::get_guild_integrations(self.0) }
/// Gets all of the guild's invites.
///
@@ -357,9 +346,7 @@ impl GuildId {
///
/// [Manage Guild]: permissions/struct.MANAGE_GUILD.html
#[inline]
- pub fn invites(&self) -> Result<Vec<RichInvite>> {
- http::get_guild_invites(self.0)
- }
+ pub fn invites(&self) -> Result<Vec<RichInvite>> { http::get_guild_invites(self.0) }
/// Kicks a [`Member`] from the guild.
///
@@ -374,9 +361,7 @@ impl GuildId {
/// Leaves the guild.
#[inline]
- pub fn leave(&self) -> Result<()> {
- http::leave_guild(self.0)
- }
+ pub fn leave(&self) -> Result<()> { http::leave_guild(self.0) }
/// Gets a user's [`Member`] for the guild by Id.
///
@@ -395,8 +380,9 @@ impl GuildId {
///
/// [`User`]: struct.User.html
#[inline]
- pub fn members<U>(&self, limit: Option<u64>, after: Option<U>)
- -> Result<Vec<Member>> where U: Into<UserId> {
+ pub fn members<U>(&self, limit: Option<u64>, after: Option<U>) -> Result<Vec<Member>>
+ where
+ U: Into<UserId>, {
http::get_guild_members(self.0, limit, after.map(|x| x.into().0))
}
@@ -405,10 +391,13 @@ impl GuildId {
/// Requires the [Move Members] permission.
///
/// [Move Members]: permissions/constant.MOVE_MEMBERS.html
- pub fn move_member<C, U>(&self, user_id: U, channel_id: C)
- -> Result<()> where C: Into<ChannelId>, U: Into<UserId> {
+ pub fn move_member<C, U>(&self, user_id: U, channel_id: C) -> Result<()>
+ where
+ C: Into<ChannelId>,
+ U: Into<UserId>, {
let mut map = Map::new();
- map.insert("channel_id".to_owned(), Value::Number(Number::from(channel_id.into().0)));
+ map.insert("channel_id".to_owned(),
+ Value::Number(Number::from(channel_id.into().0)));
http::edit_member(self.0, user_id.into().0, &map)
}
@@ -438,11 +427,9 @@ impl GuildId {
/// total, consider using [`utils::shard_id`].
///
/// [`utils::shard_id`]: ../utils/fn.shard_id.html
- #[cfg(all(feature="cache", feature="utils"))]
+ #[cfg(all(feature = "cache", feature = "utils"))]
#[inline]
- pub fn shard_id(&self) -> u64 {
- ::utils::shard_id(self.0, CACHE.read().unwrap().shard_count)
- }
+ pub fn shard_id(&self) -> u64 { ::utils::shard_id(self.0, CACHE.read().unwrap().shard_count) }
/// Returns the Id of the shard associated with the guild.
///
@@ -465,11 +452,9 @@ impl GuildId {
///
/// assert_eq!(guild_id.shard_id(17), 7);
/// ```
- #[cfg(all(feature="utils", not(feature="cache")))]
+ #[cfg(all(feature = "utils", not(feature = "cache")))]
#[inline]
- pub fn shard_id(&self, shard_count: u64) -> u64 {
- ::utils::shard_id(self.0, shard_count)
- }
+ pub fn shard_id(&self, shard_count: u64) -> u64 { ::utils::shard_id(self.0, shard_count) }
/// Starts an integration sync for the given integration Id.
///
@@ -516,69 +501,49 @@ impl GuildId {
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
#[inline]
- pub fn webhooks(&self) -> Result<Vec<Webhook>> {
- http::get_guild_webhooks(self.0)
- }
+ pub fn webhooks(&self) -> Result<Vec<Webhook>> { http::get_guild_webhooks(self.0) }
}
impl Display for GuildId {
- fn fmt(&self, f: &mut Formatter) -> FmtResult {
- Display::fmt(&self.0, f)
- }
+ fn fmt(&self, f: &mut Formatter) -> FmtResult { Display::fmt(&self.0, f) }
}
impl From<PartialGuild> for GuildId {
/// Gets the Id of a partial guild.
- fn from(guild: PartialGuild) -> GuildId {
- guild.id
- }
+ fn from(guild: PartialGuild) -> GuildId { guild.id }
}
impl<'a> From<&'a PartialGuild> for GuildId {
/// Gets the Id of a partial guild.
- fn from(guild: &PartialGuild) -> GuildId {
- guild.id
- }
+ fn from(guild: &PartialGuild) -> GuildId { guild.id }
}
impl From<GuildInfo> for GuildId {
/// Gets the Id of Guild information struct.
- fn from(guild_info: GuildInfo) -> GuildId {
- guild_info.id
- }
+ fn from(guild_info: GuildInfo) -> GuildId { guild_info.id }
}
impl<'a> From<&'a GuildInfo> for GuildId {
/// Gets the Id of Guild information struct.
- fn from(guild_info: &GuildInfo) -> GuildId {
- guild_info.id
- }
+ fn from(guild_info: &GuildInfo) -> GuildId { guild_info.id }
}
impl From<InviteGuild> for GuildId {
/// Gets the Id of Invite Guild struct.
- fn from(invite_guild: InviteGuild) -> GuildId {
- invite_guild.id
- }
+ fn from(invite_guild: InviteGuild) -> GuildId { invite_guild.id }
}
impl<'a> From<&'a InviteGuild> for GuildId {
/// Gets the Id of Invite Guild struct.
- fn from(invite_guild: &InviteGuild) -> GuildId {
- invite_guild.id
- }
+ fn from(invite_guild: &InviteGuild) -> GuildId { invite_guild.id }
}
impl From<Guild> for GuildId {
/// Gets the Id of Guild.
- fn from(live_guild: Guild) -> GuildId {
- live_guild.id
- }
+ fn from(live_guild: Guild) -> GuildId { live_guild.id }
}
impl<'a> From<&'a Guild> for GuildId {
/// Gets the Id of Guild.
- fn from(live_guild: &Guild) -> GuildId {
- live_guild.id
- }
+ fn from(live_guild: &Guild) -> GuildId { live_guild.id }
}
diff --git a/src/model/guild/integration.rs b/src/model/guild/integration.rs
index b276bc3..18da39d 100644
--- a/src/model/guild/integration.rs
+++ b/src/model/guild/integration.rs
@@ -6,7 +6,7 @@ pub struct Integration {
pub id: IntegrationId,
pub account: IntegrationAccount,
pub enabled: bool,
- #[serde(rename="expire_behaviour")]
+ #[serde(rename = "expire_behaviour")]
pub expire_behaviour: u64,
pub expire_grace_period: u64,
pub kind: String,
@@ -19,9 +19,7 @@ pub struct Integration {
impl From<Integration> for IntegrationId {
/// Gets the Id of integration.
- fn from(integration: Integration) -> IntegrationId {
- integration.id
- }
+ fn from(integration: Integration) -> IntegrationId { integration.id }
}
/// Integration account object.
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index ab817e7..dcf503d 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -1,20 +1,20 @@
use chrono::{DateTime, FixedOffset};
use std::fmt::{Display, Formatter, Result as FmtResult};
use super::deserialize_sync_user;
-use ::model::*;
+use model::*;
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
use std::borrow::Cow;
-#[cfg(feature="cache")]
-use ::CACHE;
-#[cfg(feature="cache")]
-use ::internal::prelude::*;
-#[cfg(all(feature="cache", feature="model"))]
-use ::http;
-#[cfg(all(feature="builder", feature="cache", feature="model"))]
-use ::builder::EditMember;
-#[cfg(all(feature="cache", feature="model", feature="utils"))]
-use ::utils::Colour;
+#[cfg(feature = "cache")]
+use CACHE;
+#[cfg(feature = "cache")]
+use internal::prelude::*;
+#[cfg(all(feature = "cache", feature = "model"))]
+use http;
+#[cfg(all(feature = "builder", feature = "cache", feature = "model"))]
+use builder::EditMember;
+#[cfg(all(feature = "cache", feature = "model", feature = "utils"))]
+use utils::Colour;
pub trait BanOptions {
fn dmd(&self) -> u8 { 0 }
@@ -22,41 +22,27 @@ pub trait BanOptions {
}
impl BanOptions for u8 {
- fn dmd(&self) -> u8 {
- *self
- }
+ fn dmd(&self) -> u8 { *self }
}
impl BanOptions for str {
- fn reason(&self) -> &str {
- self
- }
+ fn reason(&self) -> &str { self }
}
impl BanOptions for String {
- fn reason(&self) -> &str {
- &self
- }
+ fn reason(&self) -> &str { &self }
}
impl<'a> BanOptions for (u8, &'a str) {
- fn dmd(&self) -> u8 {
- self.0
- }
+ fn dmd(&self) -> u8 { self.0 }
- fn reason(&self) -> &str {
- self.1
- }
+ fn reason(&self) -> &str { self.1 }
}
impl BanOptions for (u8, String) {
- fn dmd(&self) -> u8 {
- self.0
- }
+ fn dmd(&self) -> u8 { self.0 }
- fn reason(&self) -> &str {
- &self.1
- }
+ fn reason(&self) -> &str { &self.1 }
}
/// Information about a member of a guild.
@@ -77,11 +63,11 @@ pub struct Member {
/// Vector of Ids of [`Role`]s given to the member.
pub roles: Vec<RoleId>,
/// Attached User struct.
- #[serde(deserialize_with="deserialize_sync_user")]
+ #[serde(deserialize_with = "deserialize_sync_user")]
pub user: Arc<RwLock<User>>,
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl Member {
/// Adds a [`Role`] to the member, editing its roles in-place if the request
/// was successful.
@@ -90,7 +76,7 @@ impl Member {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn add_role<R: Into<RoleId>>(&mut self, role_id: R) -> Result<()> {
let role_id = role_id.into();
@@ -115,7 +101,7 @@ impl Member {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn add_roles(&mut self, role_ids: &[RoleId]) -> Result<()> {
self.roles.extend_from_slice(role_ids);
@@ -127,7 +113,7 @@ impl Member {
self.roles.retain(|r| !role_ids.contains(r));
Err(why)
- }
+ },
}
}
@@ -144,19 +130,22 @@ impl Member {
/// [`ModelError::GuildNotFound`]: enum.ModelError.html#variant.GuildNotFound
///
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn ban<BO: BanOptions>(&self, ban_options: BO) -> Result<()> {
let reason = ban_options.reason();
-
+
if reason.len() > 512 {
return Err(Error::ExceededLimit);
}
- http::ban_user(self.guild_id.0, self.user.read().unwrap().id.0, ban_options.dmd(), &*reason)
+ http::ban_user(self.guild_id.0,
+ self.user.read().unwrap().id.0,
+ ban_options.dmd(),
+ &*reason)
}
/// Determines the member's colour.
- #[cfg(all(feature="cache", feature="utils"))]
+ #[cfg(all(feature = "cache", feature = "utils"))]
pub fn colour(&self) -> Option<Colour> {
let cache = CACHE.read().unwrap();
let guild = match cache.guilds.get(&self.guild_id) {
@@ -172,7 +161,10 @@ impl Member {
let default = Colour::default();
- roles.iter().find(|r| r.colour.0 != default.0).map(|r| r.colour)
+ roles
+ .iter()
+ .find(|r| r.colour.0 != default.0)
+ .map(|r| r.colour)
}
/// Calculates the member's display name.
@@ -180,7 +172,8 @@ impl Member {
/// The nickname takes priority over the member's username if it exists.
#[inline]
pub fn display_name(&self) -> Cow<String> {
- self.nick.as_ref()
+ self.nick
+ .as_ref()
.map(Cow::Borrowed)
.unwrap_or_else(|| Cow::Owned(self.user.read().unwrap().name.clone()))
}
@@ -188,7 +181,9 @@ impl Member {
/// Returns the DiscordTag of a Member, taking possible nickname into account.
#[inline]
pub fn distinct(&self) -> String {
- format!("{}#{}", self.display_name(), self.user.read().unwrap().discriminator)
+ format!("{}#{}",
+ self.display_name(),
+ self.user.read().unwrap().discriminator)
}
/// Edits the member with the given data. See [`Guild::edit_member`] for
@@ -199,7 +194,7 @@ impl Member {
///
/// [`Guild::edit_member`]: ../model/struct.Guild.html#method.edit_member
/// [`EditMember`]: ../builder/struct.EditMember.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn edit<F: FnOnce(EditMember) -> EditMember>(&self, f: F) -> Result<()> {
let map = f(EditMember::default()).0;
@@ -240,7 +235,7 @@ impl Member {
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
pub fn kick(&self) -> Result<()> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::KICK_MEMBERS;
@@ -265,7 +260,8 @@ impl Member {
///
/// ```rust,ignore
/// // assuming there's a `member` variable gotten from anything.
- /// println!("The permission bits for the member are: {}", member.permissions().expect("permissions").bits);
+ /// println!("The permission bits for the member are: {}",
+ /// member.permissions().expect("permissions").bits);
/// ```
///
/// # Errors
@@ -274,7 +270,7 @@ impl Member {
/// found in the cache.
///
/// [`ModelError::GuildNotFound`]: enum.ModelError.html#variant.GuildNotFound
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn permissions(&self) -> Result<Permissions> {
let guild = match self.guild_id.find() {
Some(guild) => guild,
@@ -293,7 +289,7 @@ impl Member {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn remove_role<R: Into<RoleId>>(&mut self, role_id: R) -> Result<()> {
let role_id = role_id.into();
@@ -317,7 +313,7 @@ impl Member {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn remove_roles(&mut self, role_ids: &[RoleId]) -> Result<()> {
self.roles.retain(|r| !role_ids.contains(r));
@@ -338,25 +334,29 @@ impl Member {
/// This is shorthand for manually searching through the CACHE.
///
/// If role data can not be found for the member, then `None` is returned.
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn roles(&self) -> Option<Vec<Role>> {
- CACHE.read().unwrap()
+ CACHE
+ .read()
+ .unwrap()
.guilds
.values()
- .find(|guild| guild
- .read()
- .unwrap()
- .members
- .values()
- .any(|m| m.user.read().unwrap().id == self.user.read().unwrap().id && m.joined_at == self.joined_at))
- .map(|guild| guild
- .read()
- .unwrap()
- .roles
- .values()
- .filter(|role| self.roles.contains(&role.id))
- .cloned()
- .collect())
+ .find(|guild| {
+ guild.read().unwrap().members.values().any(|m| {
+ m.user.read().unwrap().id == self.user.read().unwrap().id &&
+ m.joined_at == self.joined_at
+ })
+ })
+ .map(|guild| {
+ guild
+ .read()
+ .unwrap()
+ .roles
+ .values()
+ .filter(|role| self.roles.contains(&role.id))
+ .cloned()
+ .collect()
+ })
}
/// Unbans the [`User`] from the guild.
@@ -371,7 +371,7 @@ impl Member {
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn unban(&self) -> Result<()> {
http::remove_ban(self.guild_id.0, self.user.read().unwrap().id.0)
}
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index 17d88e6..70d82cb 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -20,16 +20,16 @@ use chrono::{DateTime, FixedOffset};
use serde::de::Error as DeError;
use serde_json;
use super::utils::*;
-use ::model::*;
+use model::*;
-#[cfg(feature="cache")]
-use ::CACHE;
-#[cfg(feature="model")]
-use ::http;
-#[cfg(feature="model")]
-use ::builder::{EditGuild, EditMember, EditRole};
-#[cfg(feature="model")]
-use ::constants::LARGE_THRESHOLD;
+#[cfg(feature = "cache")]
+use CACHE;
+#[cfg(feature = "model")]
+use http;
+#[cfg(feature = "model")]
+use builder::{EditGuild, EditMember, EditRole};
+#[cfg(feature = "model")]
+use constants::LARGE_THRESHOLD;
/// A representation of a banning of a user.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash)]
@@ -121,9 +121,9 @@ pub struct Guild {
pub voice_states: HashMap<UserId, VoiceState>,
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl Guild {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
fn has_perms(&self, mut permissions: Permissions) -> Result<bool> {
let member = match self.members.get(&CACHE.read().unwrap().user.id) {
Some(member) => member,
@@ -160,18 +160,18 @@ impl Guild {
/// Returns a [`ModelError::DeleteMessageDaysAmount`] if the number of
/// days' worth of messages to delete is over the maximum.
///
- /// [`ModelError::DeleteMessageDaysAmount`]: enum.ModelError.html#variant.DeleteMessageDaysAmount
+ /// [`ModelError::DeleteMessageDaysAmount`]:
+ /// enum.ModelError.html#variant.DeleteMessageDaysAmount
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [`Guild::ban`]: struct.Guild.html#method.ban
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
- pub fn ban<U: Into<UserId>>(&self, user: U, delete_message_days: u8)
- -> Result<()> {
+ pub fn ban<U: Into<UserId>>(&self, user: U, delete_message_days: u8) -> Result<()> {
if delete_message_days > 7 {
return Err(Error::Model(ModelError::DeleteMessageDaysAmount(delete_message_days)));
}
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::BAN_MEMBERS;
@@ -196,7 +196,7 @@ impl Guild {
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
pub fn bans(&self) -> Result<Vec<Ban>> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::BAN_MEMBERS;
@@ -212,17 +212,13 @@ impl Guild {
///
/// [`AuditLogs`]: audit_log/struct.AuditLogs.html
#[inline]
- pub fn audit_logs(&self) -> Result<AuditLogs> {
- self.id.audit_logs()
- }
+ pub fn audit_logs(&self) -> Result<AuditLogs> { self.id.audit_logs() }
/// Gets all of the guild's channels over the REST API.
///
/// [`Guild`]: struct.Guild.html
#[inline]
- pub fn channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
- self.id.channels()
- }
+ pub fn channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> { self.id.channels() }
/// Creates a guild with the data provided.
///
@@ -282,7 +278,7 @@ impl Guild {
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html
pub fn create_channel(&self, name: &str, kind: ChannelType) -> Result<GuildChannel> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::MANAGE_CHANNELS;
@@ -325,7 +321,8 @@ impl Guild {
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
#[inline]
pub fn create_integration<I>(&self, integration_id: I, kind: &str) -> Result<()>
- where I: Into<IntegrationId> {
+ where
+ I: Into<IntegrationId>, {
self.id.create_integration(integration_id, kind)
}
@@ -352,8 +349,9 @@ impl Guild {
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
pub fn create_role<F>(&self, f: F) -> Result<Role>
- where F: FnOnce(EditRole) -> EditRole {
- #[cfg(feature="cache")]
+ where
+ F: FnOnce(EditRole) -> EditRole, {
+ #[cfg(feature = "cache")]
{
let req = permissions::MANAGE_ROLES;
@@ -377,7 +375,7 @@ impl Guild {
///
/// [`ModelError::InvalidUser`]: enum.ModelError.html#variant.InvalidUser
pub fn delete(&self) -> Result<PartialGuild> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
if self.owner_id != CACHE.read().unwrap().user.id {
let req = permissions::MANAGE_GUILD;
@@ -454,8 +452,9 @@ impl Guild {
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
pub fn edit<F>(&mut self, f: F) -> Result<()>
- where F: FnOnce(EditGuild) -> EditGuild {
- #[cfg(feature="cache")]
+ where
+ F: FnOnce(EditGuild) -> EditGuild, {
+ #[cfg(feature = "cache")]
{
let req = permissions::MANAGE_GUILD;
@@ -516,7 +515,9 @@ impl Guild {
/// ```
#[inline]
pub fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()>
- where F: FnOnce(EditMember) -> EditMember, U: Into<UserId> {
+ where
+ F: FnOnce(EditMember) -> EditMember,
+ U: Into<UserId>, {
self.id.edit_member(user_id, f)
}
@@ -535,7 +536,7 @@ impl Guild {
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Change Nickname]: permissions/constant.CHANGE_NICKNAME.html
pub fn edit_nickname(&self, new_nickname: Option<&str>) -> Result<()> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::CHANGE_NICKNAME;
@@ -562,7 +563,9 @@ impl Guild {
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
#[inline]
pub fn edit_role<F, R>(&self, role_id: R, f: F) -> Result<Role>
- where F: FnOnce(EditRole) -> EditRole, R: Into<RoleId> {
+ where
+ F: FnOnce(EditRole) -> EditRole,
+ R: Into<RoleId>, {
self.id.edit_role(role_id, f)
}
@@ -572,9 +575,7 @@ impl Guild {
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
- self.id.emoji(emoji_id)
- }
+ pub fn emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> { self.id.emoji(emoji_id) }
/// Gets a list of all of the guild's emojis.
///
@@ -582,31 +583,26 @@ impl Guild {
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn emojis(&self) -> Result<Vec<Emoji>> {
- self.id.emojis()
- }
+ pub fn emojis(&self) -> Result<Vec<Emoji>> { self.id.emojis() }
/// Gets a partial amount of guild data by its Id.
///
/// Requires that the current user be in the guild.
#[inline]
- pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> {
- guild_id.into().get()
- }
+ pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> { guild_id.into().get() }
/// Returns the formatted URL of the guild's icon, if one exists.
pub fn icon_url(&self) -> Option<String> {
- self.icon.as_ref().map(|icon|
- format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
+ self.icon
+ .as_ref()
+ .map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
}
/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
#[inline]
- pub fn integrations(&self) -> Result<Vec<Integration>> {
- self.id.integrations()
- }
+ pub fn integrations(&self) -> Result<Vec<Integration>> { self.id.integrations() }
/// Retrieves the active invites for the guild.
///
@@ -620,7 +616,7 @@ impl Guild {
/// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
pub fn invites(&self) -> Result<Vec<RichInvite>> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::MANAGE_GUILD;
@@ -635,9 +631,7 @@ impl Guild {
/// Checks if the guild is 'large'. A guild is considered large if it has
/// more than 250 members.
#[inline]
- pub fn is_large(&self) -> bool {
- self.members.len() > LARGE_THRESHOLD as usize
- }
+ pub fn is_large(&self) -> bool { self.members.len() > LARGE_THRESHOLD as usize }
/// Kicks a [`Member`] from the guild.
///
@@ -646,24 +640,18 @@ impl Guild {
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
#[inline]
- pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
- self.id.kick(user_id)
- }
+ pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> { self.id.kick(user_id) }
/// Leaves the guild.
#[inline]
- pub fn leave(&self) -> Result<()> {
- self.id.leave()
- }
+ pub fn leave(&self) -> Result<()> { self.id.leave() }
/// Gets a user's [`Member`] for the guild by Id.
///
/// [`Guild`]: struct.Guild.html
/// [`Member`]: struct.Member.html
#[inline]
- pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
- self.id.member(user_id)
- }
+ pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> { self.id.member(user_id) }
/// Gets a list of the guild's members.
///
@@ -673,12 +661,14 @@ impl Guild {
///
/// [`User`]: struct.User.html
#[inline]
- pub fn members<U>(&self, limit: Option<u64>, after: Option<U>)
- -> Result<Vec<Member>> where U: Into<UserId> {
+ pub fn members<U>(&self, limit: Option<u64>, after: Option<U>) -> Result<Vec<Member>>
+ where
+ U: Into<UserId>, {
self.id.members(limit, after)
}
- /// Gets a list of all the members (satisfying the status provided to the function) in this guild.
+ /// Gets a list of all the members (satisfying the status provided to the function) in this
+ /// guild.
pub fn members_with_status(&self, status: OnlineStatus) -> Vec<&Member> {
let mut members = vec![];
@@ -735,9 +725,12 @@ impl Guild {
};
name_matches && discrim_matches
- }).or_else(|| self.members.values().find(|member| {
- member.nick.as_ref().map_or(false, |nick| nick == name)
- }))
+ })
+ .or_else(|| {
+ self.members
+ .values()
+ .find(|member| member.nick.as_ref().map_or(false, |nick| nick == name))
+ })
}
/// Moves a member to a specific voice channel.
@@ -747,15 +740,19 @@ impl Guild {
/// [Move Members]: permissions/constant.MOVE_MEMBERS.html
#[inline]
pub fn move_member<C, U>(&self, user_id: U, channel_id: C) -> Result<()>
- where C: Into<ChannelId>, U: Into<UserId> {
+ where
+ C: Into<ChannelId>,
+ U: Into<UserId>, {
self.id.move_member(user_id, channel_id)
}
/// Calculate a [`User`]'s permissions in a given channel in the guild.
///
/// [`User`]: struct.User.html
- pub fn permissions_for<C, U>(&self, channel_id: C, user_id: U)
- -> Permissions where C: Into<ChannelId>, U: Into<UserId> {
+ pub fn permissions_for<C, U>(&self, channel_id: C, user_id: U) -> Permissions
+ where
+ C: Into<ChannelId>,
+ U: Into<UserId>, {
use super::permissions::*;
let user_id = user_id.into();
@@ -808,8 +805,8 @@ impl Guild {
// If this is a text channel, then throw out voice permissions.
if channel.kind == ChannelType::Text {
- permissions &= !(CONNECT | SPEAK | MUTE_MEMBERS |
- DEAFEN_MEMBERS | MOVE_MEMBERS | USE_VAD);
+ permissions &=
+ !(CONNECT | SPEAK | MUTE_MEMBERS | DEAFEN_MEMBERS | MOVE_MEMBERS | USE_VAD);
}
// Apply the permission overwrites for the channel for each of the
@@ -853,17 +850,14 @@ impl Guild {
// If the member does not have the `SEND_MESSAGES` permission, then
// throw out message-able permissions.
if !permissions.contains(SEND_MESSAGES) {
- permissions &= !(SEND_TTS_MESSAGES |
- MENTION_EVERYONE |
- EMBED_LINKS |
- ATTACH_FILES);
+ permissions &= !(SEND_TTS_MESSAGES | MENTION_EVERYONE | EMBED_LINKS | ATTACH_FILES);
}
// If the member does not have the `READ_MESSAGES` permission, then
// throw out actionable permissions.
if !permissions.contains(READ_MESSAGES) {
- permissions &= KICK_MEMBERS | BAN_MEMBERS | ADMINISTRATOR |
- MANAGE_GUILD | CHANGE_NICKNAME | MANAGE_NICKNAMES;
+ permissions &= KICK_MEMBERS | BAN_MEMBERS | ADMINISTRATOR | MANAGE_GUILD |
+ CHANGE_NICKNAME | MANAGE_NICKNAMES;
}
permissions
@@ -886,7 +880,7 @@ impl Guild {
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
pub fn prune_count(&self, days: u16) -> Result<GuildPrune> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::KICK_MEMBERS;
@@ -908,11 +902,9 @@ impl Guild {
/// total, consider using [`utils::shard_id`].
///
/// [`utils::shard_id`]: ../utils/fn.shard_id.html
- #[cfg(all(feature="cache", feature="utils"))]
+ #[cfg(all(feature = "cache", feature = "utils"))]
#[inline]
- pub fn shard_id(&self) -> u64 {
- self.id.shard_id()
- }
+ pub fn shard_id(&self) -> u64 { self.id.shard_id() }
/// Returns the Id of the shard associated with the guild.
///
@@ -934,16 +926,15 @@ impl Guild {
///
/// assert_eq!(guild.shard_id(17), 7);
/// ```
- #[cfg(all(feature="utils", not(feature="cache")))]
+ #[cfg(all(feature = "utils", not(feature = "cache")))]
#[inline]
- pub fn shard_id(&self, shard_count: u64) -> u64 {
- self.id.shard_id(shard_count)
- }
+ pub fn shard_id(&self, shard_count: u64) -> u64 { self.id.shard_id(shard_count) }
/// Returns the formatted URL of the guild's splash image, if one exists.
pub fn splash_url(&self) -> Option<String> {
- self.icon.as_ref().map(|icon|
- format!(cdn!("/splashes/{}/{}.webp"), self.id, icon))
+ self.icon
+ .as_ref()
+ .map(|icon| format!(cdn!("/splashes/{}/{}.webp"), self.id, icon))
}
/// Starts an integration sync for the given integration Id.
@@ -972,7 +963,7 @@ impl Guild {
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
pub fn start_prune(&self, days: u16) -> Result<GuildPrune> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::KICK_MEMBERS;
@@ -997,7 +988,7 @@ impl Guild {
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
{
let req = permissions::BAN_MEMBERS;
@@ -1015,9 +1006,7 @@ impl Guild {
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
#[inline]
- pub fn webhooks(&self) -> Result<Vec<Webhook>> {
- self.id.webhooks()
- }
+ pub fn webhooks(&self) -> Result<Vec<Webhook>> { self.id.webhooks() }
}
impl<'de> Deserialize<'de> for Guild {
@@ -1032,7 +1021,8 @@ impl<'de> Deserialize<'de> for Guild {
if let Some(array) = map.get_mut("channels").and_then(|x| x.as_array_mut()) {
for value in array {
if let Some(channel) = value.as_object_mut() {
- channel.insert("guild_id".to_owned(), Value::Number(Number::from(guild_id)));
+ channel
+ .insert("guild_id".to_owned(), Value::Number(Number::from(guild_id)));
}
}
}
@@ -1047,7 +1037,10 @@ impl<'de> Deserialize<'de> for Guild {
}
let afk_channel_id = match map.remove("afk_channel_id") {
- Some(v) => serde_json::from_value::<Option<ChannelId>>(v).map_err(DeError::custom)?,
+ Some(v) => {
+ serde_json::from_value::<Option<ChannelId>>(v)
+ .map_err(DeError::custom)?
+ },
None => None,
};
let afk_timeout = map.remove("afk_timeout")
@@ -1132,28 +1125,28 @@ impl<'de> Deserialize<'de> for Guild {
.map_err(DeError::custom)?;
Ok(Self {
- afk_channel_id: afk_channel_id,
- afk_timeout: afk_timeout,
- channels: channels,
- default_message_notifications: default_message_notifications,
- emojis: emojis,
- features: features,
- icon: icon,
- id: id,
- joined_at: joined_at,
- large: large,
- member_count: member_count,
- members: members,
- mfa_level: mfa_level,
- name: name,
- owner_id: owner_id,
- presences: presences,
- region: region,
- roles: roles,
- splash: splash,
- verification_level: verification_level,
- voice_states: voice_states,
- })
+ afk_channel_id: afk_channel_id,
+ afk_timeout: afk_timeout,
+ channels: channels,
+ default_message_notifications: default_message_notifications,
+ emojis: emojis,
+ features: features,
+ icon: icon,
+ id: id,
+ joined_at: joined_at,
+ large: large,
+ member_count: member_count,
+ members: members,
+ mfa_level: mfa_level,
+ name: name,
+ owner_id: owner_id,
+ presences: presences,
+ region: region,
+ roles: roles,
+ splash: splash,
+ verification_level: verification_level,
+ voice_states: voice_states,
+ })
}
}
@@ -1193,39 +1186,35 @@ pub struct GuildInfo {
pub permissions: Permissions,
}
-#[cfg(any(feature="model", feature="utils"))]
+#[cfg(any(feature = "model", feature = "utils"))]
impl GuildInfo {
/// Returns the formatted URL of the guild's icon, if the guild has an icon.
pub fn icon_url(&self) -> Option<String> {
- self.icon.as_ref().map(|icon|
- format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
+ self.icon
+ .as_ref()
+ .map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
}
}
impl From<PartialGuild> for GuildContainer {
- fn from(guild: PartialGuild) -> GuildContainer {
- GuildContainer::Guild(guild)
- }
+ fn from(guild: PartialGuild) -> GuildContainer { GuildContainer::Guild(guild) }
}
impl From<GuildId> for GuildContainer {
- fn from(guild_id: GuildId) -> GuildContainer {
- GuildContainer::Id(guild_id)
- }
+ fn from(guild_id: GuildId) -> GuildContainer { GuildContainer::Id(guild_id) }
}
impl From<u64> for GuildContainer {
- fn from(id: u64) -> GuildContainer {
- GuildContainer::Id(GuildId(id))
- }
+ fn from(id: u64) -> GuildContainer { GuildContainer::Id(GuildId(id)) }
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl InviteGuild {
/// Returns the formatted URL of the guild's splash image, if one exists.
pub fn splash_url(&self) -> Option<String> {
- self.icon.as_ref().map(|icon|
- format!(cdn!("/splashes/{}/{}.webp"), self.id, icon))
+ self.icon
+ .as_ref()
+ .map(|icon| format!(cdn!("/splashes/{}/{}.webp"), self.id, icon))
}
}
@@ -1251,7 +1240,7 @@ pub enum GuildStatus {
Offline(GuildUnavailable),
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl GuildStatus {
/// Retrieves the Id of the inner [`Guild`].
///
diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs
index 26d4257..d070e54 100644
--- a/src/model/guild/partial_guild.rs
+++ b/src/model/guild/partial_guild.rs
@@ -1,8 +1,8 @@
use super::super::utils::{deserialize_emojis, deserialize_roles};
-use ::model::*;
+use model::*;
-#[cfg(feature="model")]
-use ::builder::{EditGuild, EditMember, EditRole};
+#[cfg(feature = "model")]
+use builder::{EditGuild, EditMember, EditRole};
/// Partial information about a [`Guild`]. This does not include information
/// like member data.
@@ -16,7 +16,7 @@ pub struct PartialGuild {
pub default_message_notifications: u64,
pub embed_channel_id: Option<ChannelId>,
pub embed_enabled: bool,
- #[serde(deserialize_with="deserialize_emojis")]
+ #[serde(deserialize_with = "deserialize_emojis")]
pub emojis: HashMap<EmojiId, Emoji>,
pub features: Vec<Feature>,
pub icon: Option<String>,
@@ -24,13 +24,13 @@ pub struct PartialGuild {
pub name: String,
pub owner_id: UserId,
pub region: String,
- #[serde(deserialize_with="deserialize_roles")]
+ #[serde(deserialize_with = "deserialize_roles")]
pub roles: HashMap<RoleId, Role>,
pub splash: Option<String>,
pub verification_level: VerificationLevel,
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl PartialGuild {
/// Ban a [`User`] from the guild. All messages by the
/// user within the last given number of days given will be deleted. This
@@ -52,7 +52,8 @@ impl PartialGuild {
/// Returns a [`ModelError::DeleteMessageDaysAmount`] if the number of
/// days' worth of messages to delete is over the maximum.
///
- /// [`ModelError::DeleteMessageDaysAmount`]: enum.ModelError.html#variant.DeleteMessageDaysAmount
+ /// [`ModelError::DeleteMessageDaysAmount`]:
+ /// enum.ModelError.html#variant.DeleteMessageDaysAmount
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
pub fn ban<U: Into<UserId>>(&self, user: U, delete_message_days: u8) -> Result<()> {
@@ -69,17 +70,13 @@ impl PartialGuild {
///
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
#[inline]
- pub fn bans(&self) -> Result<Vec<Ban>> {
- self.id.bans()
- }
+ pub fn bans(&self) -> Result<Vec<Ban>> { self.id.bans() }
/// Gets all of the guild's channels over the REST API.
///
/// [`Guild`]: struct.Guild.html
#[inline]
- pub fn channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> {
- self.id.channels()
- }
+ pub fn channels(&self) -> Result<HashMap<ChannelId, GuildChannel>> { self.id.channels() }
/// Creates a [`GuildChannel`] in the guild.
///
@@ -134,7 +131,8 @@ impl PartialGuild {
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
#[inline]
pub fn create_integration<I>(&self, integration_id: I, kind: &str) -> Result<()>
- where I: Into<IntegrationId> {
+ where
+ I: Into<IntegrationId>, {
self.id.create_integration(integration_id, kind)
}
@@ -162,9 +160,7 @@ impl PartialGuild {
///
/// **Note**: Requires the current user to be the owner of the guild.
#[inline]
- pub fn delete(&self) -> Result<PartialGuild> {
- self.id.delete()
- }
+ pub fn delete(&self) -> Result<PartialGuild> { self.id.delete() }
/// Deletes an [`Emoji`] from the guild.
///
@@ -209,7 +205,8 @@ impl PartialGuild {
///
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
pub fn edit<F>(&mut self, f: F) -> Result<()>
- where F: FnOnce(EditGuild) -> EditGuild {
+ where
+ F: FnOnce(EditGuild) -> EditGuild, {
match self.id.edit(f) {
Ok(guild) => {
self.afk_channel_id = guild.afk_channel_id;
@@ -264,7 +261,9 @@ impl PartialGuild {
/// ```
#[inline]
pub fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()>
- where F: FnOnce(EditMember) -> EditMember, U: Into<UserId> {
+ where
+ F: FnOnce(EditMember) -> EditMember,
+ U: Into<UserId>, {
self.id.edit_member(user_id, f)
}
@@ -293,9 +292,7 @@ impl PartialGuild {
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> {
- self.id.emoji(emoji_id)
- }
+ pub fn emoji<E: Into<EmojiId>>(&self, emoji_id: E) -> Result<Emoji> { self.id.emoji(emoji_id) }
/// Gets a list of all of the guild's emojis.
///
@@ -303,17 +300,13 @@ impl PartialGuild {
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
#[inline]
- pub fn emojis(&self) -> Result<Vec<Emoji>> {
- self.id.emojis()
- }
+ pub fn emojis(&self) -> Result<Vec<Emoji>> { self.id.emojis() }
/// Gets a partial amount of guild data by its Id.
///
/// Requires that the current user be in the guild.
#[inline]
- pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> {
- guild_id.into().get()
- }
+ pub fn get<G: Into<GuildId>>(guild_id: G) -> Result<PartialGuild> { guild_id.into().get() }
/// Kicks a [`Member`] from the guild.
///
@@ -322,23 +315,20 @@ impl PartialGuild {
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
#[inline]
- pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
- self.id.kick(user_id)
- }
+ pub fn kick<U: Into<UserId>>(&self, user_id: U) -> Result<()> { self.id.kick(user_id) }
/// Returns a formatted URL of the guild's icon, if the guild has an icon.
pub fn icon_url(&self) -> Option<String> {
- self.icon.as_ref().map(|icon|
- format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
+ self.icon
+ .as_ref()
+ .map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon))
}
/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
#[inline]
- pub fn integrations(&self) -> Result<Vec<Integration>> {
- self.id.integrations()
- }
+ pub fn integrations(&self) -> Result<Vec<Integration>> { self.id.integrations() }
/// Gets all of the guild's invites.
///
@@ -346,23 +336,17 @@ impl PartialGuild {
///
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
#[inline]
- pub fn invites(&self) -> Result<Vec<RichInvite>> {
- self.id.invites()
- }
+ pub fn invites(&self) -> Result<Vec<RichInvite>> { self.id.invites() }
/// Leaves the guild.
#[inline]
- pub fn leave(&self) -> Result<()> {
- self.id.leave()
- }
+ pub fn leave(&self) -> Result<()> { self.id.leave() }
/// Gets a user's [`Member`] for the guild by Id.
///
/// [`Guild`]: struct.Guild.html
/// [`Member`]: struct.Member.html
- pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> {
- self.id.member(user_id)
- }
+ pub fn member<U: Into<UserId>>(&self, user_id: U) -> Result<Member> { self.id.member(user_id) }
/// Gets a list of the guild's members.
///
@@ -371,8 +355,9 @@ impl PartialGuild {
/// [`User`]'s Id.
///
/// [`User`]: struct.User.html
- pub fn members<U>(&self, limit: Option<u64>, after: Option<U>)
- -> Result<Vec<Member>> where U: Into<UserId> {
+ pub fn members<U>(&self, limit: Option<u64>, after: Option<U>) -> Result<Vec<Member>>
+ where
+ U: Into<UserId>, {
self.id.members(limit, after)
}
@@ -383,7 +368,9 @@ impl PartialGuild {
/// [Move Members]: permissions/constant.MOVE_MEMBERS.html
#[inline]
pub fn move_member<C, U>(&self, user_id: U, channel_id: C) -> Result<()>
- where C: Into<ChannelId>, U: Into<UserId> {
+ where
+ C: Into<ChannelId>,
+ U: Into<UserId>, {
self.id.move_member(user_id, channel_id)
}
@@ -395,9 +382,7 @@ impl PartialGuild {
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
#[inline]
- pub fn prune_count(&self, days: u16) -> Result<GuildPrune> {
- self.id.prune_count(days)
- }
+ pub fn prune_count(&self, days: u16) -> Result<GuildPrune> { self.id.prune_count(days) }
/// Returns the Id of the shard associated with the guild.
///
@@ -409,11 +394,9 @@ impl PartialGuild {
/// total, consider using [`utils::shard_id`].
///
/// [`utils::shard_id`]: ../utils/fn.shard_id.html
- #[cfg(all(feature="cache", feature="utils"))]
+ #[cfg(all(feature = "cache", feature = "utils"))]
#[inline]
- pub fn shard_id(&self) -> u64 {
- self.id.shard_id()
- }
+ pub fn shard_id(&self) -> u64 { self.id.shard_id() }
/// Returns the Id of the shard associated with the guild.
///
@@ -435,16 +418,15 @@ impl PartialGuild {
///
/// assert_eq!(guild.shard_id(17), 7);
/// ```
- #[cfg(all(feature="utils", not(feature="cache")))]
+ #[cfg(all(feature = "utils", not(feature = "cache")))]
#[inline]
- pub fn shard_id(&self, shard_count: u64) -> u64 {
- self.id.shard_id(shard_count)
- }
+ pub fn shard_id(&self, shard_count: u64) -> u64 { self.id.shard_id(shard_count) }
/// Returns the formatted URL of the guild's splash image, if one exists.
pub fn splash_url(&self) -> Option<String> {
- self.icon.as_ref().map(|icon|
- format!(cdn!("/splashes/{}/{}.webp"), self.id, icon))
+ self.icon
+ .as_ref()
+ .map(|icon| format!(cdn!("/splashes/{}/{}.webp"), self.id, icon))
}
/// Starts an integration sync for the given integration Id.
@@ -464,9 +446,7 @@ impl PartialGuild {
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
#[inline]
- pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
- self.id.unban(user_id)
- }
+ pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> { self.id.unban(user_id) }
/// Retrieves the guild's webhooks.
///
@@ -474,7 +454,5 @@ impl PartialGuild {
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
#[inline]
- pub fn webhooks(&self) -> Result<Vec<Webhook>> {
- self.id.webhooks()
- }
+ pub fn webhooks(&self) -> Result<Vec<Webhook>> { self.id.webhooks() }
}
diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs
index c7adf0a..3f74498 100644
--- a/src/model/guild/role.rs
+++ b/src/model/guild/role.rs
@@ -1,15 +1,15 @@
use std::cmp::Ordering;
use std::fmt::{Display, Formatter, Result as FmtResult};
-use ::model::*;
+use model::*;
-#[cfg(feature="cache")]
-use ::CACHE;
-#[cfg(all(feature="builder", feature="cache", feature="model"))]
-use ::builder::EditRole;
-#[cfg(feature="cache")]
-use ::internal::prelude::*;
-#[cfg(all(feature="cache", feature="model"))]
-use ::http;
+#[cfg(feature = "cache")]
+use CACHE;
+#[cfg(all(feature = "builder", feature = "cache", feature = "model"))]
+use builder::EditRole;
+#[cfg(feature = "cache")]
+use internal::prelude::*;
+#[cfg(all(feature = "cache", feature = "model"))]
+use http;
/// Information about a role within a guild. A role represents a set of
/// permissions, and can be attached to one or multiple users. A role has
@@ -23,12 +23,12 @@ pub struct Role {
pub id: RoleId,
/// The colour of the role. This is an ergonomic representation of the inner
/// value.
- #[cfg(feature="utils")]
- #[serde(rename="color")]
+ #[cfg(feature = "utils")]
+ #[serde(rename = "color")]
pub colour: Colour,
/// The colour of the role.
- #[cfg(not(feature="utils"))]
- #[serde(rename="color")]
+ #[cfg(not(feature = "utils"))]
+ #[serde(rename = "color")]
pub colour: u32,
/// Indicator of whether the role is pinned above lesser roles.
///
@@ -62,18 +62,16 @@ pub struct Role {
pub position: i64,
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl Role {
/// Deletes the role.
///
/// **Note** Requires the [Manage Roles] permission.
///
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
#[inline]
- pub fn delete(&self) -> Result<()> {
- http::delete_role(self.find_guild()?.0, self.id.0)
- }
+ pub fn delete(&self) -> Result<()> { http::delete_role(self.find_guild()?.0, self.id.0) }
/// Edits a [`Role`], optionally setting its new fields.
///
@@ -93,9 +91,10 @@ impl Role {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
- #[cfg(all(feature="builder", feature="cache"))]
+ #[cfg(all(feature = "builder", feature = "cache"))]
pub fn edit<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role> {
- self.find_guild().and_then(|guild_id| guild_id.edit_role(self.id, f))
+ self.find_guild()
+ .and_then(|guild_id| guild_id.edit_role(self.id, f))
}
/// Searches the cache for the guild that owns the role.
@@ -106,7 +105,7 @@ impl Role {
/// that contains the role.
///
/// [`ModelError::GuildNotFound`]: enum.ModelError.html#variant.GuildNotFound
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn find_guild(&self) -> Result<GuildId> {
for guild in CACHE.read().unwrap().guilds.values() {
let guild = guild.read().unwrap();
@@ -130,8 +129,7 @@ impl Role {
/// The 'precise' argument is used to check if the role's permissions are
/// precisely equivalent to the given permissions. If you need only check
/// that the role has at least the given permissions, pass `false`.
- pub fn has_permissions(&self, permissions: Permissions, precise: bool)
- -> bool {
+ pub fn has_permissions(&self, permissions: Permissions, precise: bool) -> bool {
if precise {
self.permissions == permissions
} else {
@@ -143,9 +141,7 @@ impl Role {
impl Display for Role {
/// Format a mention for the role, pinging its members.
// This is in the format of: `<@&ROLE_ID>`.
- fn fmt(&self, f: &mut Formatter) -> FmtResult {
- Display::fmt(&self.mention(), f)
- }
+ fn fmt(&self, f: &mut Formatter) -> FmtResult { Display::fmt(&self.mention(), f) }
}
impl Eq for Role {}
@@ -161,21 +157,17 @@ impl Ord for Role {
}
impl PartialEq for Role {
- fn eq(&self, other: &Role) -> bool {
- self.id == other.id
- }
+ fn eq(&self, other: &Role) -> bool { self.id == other.id }
}
impl PartialOrd for Role {
- fn partial_cmp(&self, other: &Role) -> Option<Ordering> {
- Some(self.cmp(other))
- }
+ fn partial_cmp(&self, other: &Role) -> Option<Ordering> { Some(self.cmp(other)) }
}
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
impl RoleId {
/// Search the cache for the role.
- #[cfg(feature="cache")]
+ #[cfg(feature = "cache")]
pub fn find(&self) -> Option<Role> {
let cache = CACHE.read().unwrap();
@@ -196,21 +188,15 @@ impl RoleId {
}
impl Display for RoleId {
- fn fmt(&self, f: &mut Formatter) -> FmtResult {
- Display::fmt(&self.0, f)
- }
+ fn fmt(&self, f: &mut Formatter) -> FmtResult { Display::fmt(&self.0, f) }
}
impl From<Role> for RoleId {
/// Gets the Id of a role.
- fn from(role: Role) -> RoleId {
- role.id
- }
+ fn from(role: Role) -> RoleId { role.id }
}
impl<'a> From<&'a Role> for RoleId {
/// Gets the Id of a role.
- fn from(role: &Role) -> RoleId {
- role.id
- }
+ fn from(role: &Role) -> RoleId { role.id }
}