diff options
| author | Zeyla Hellyer <[email protected]> | 2017-08-18 16:14:32 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-08-18 17:52:53 -0700 |
| commit | e4113570967a1fb13539efbfa2cf7285b19d95ba (patch) | |
| tree | 06bb020fcfaa5f8323454dfb525272314a900186 /src/model | |
| parent | Move Clippy lints to a cfg_attr (diff) | |
| download | serenity-e4113570967a1fb13539efbfa2cf7285b19d95ba.tar.xz serenity-e4113570967a1fb13539efbfa2cf7285b19d95ba.zip | |
Apply rustfmt
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/channel/channel_id.rs | 8 | ||||
| -rw-r--r-- | src/model/channel/group.rs | 15 | ||||
| -rw-r--r-- | src/model/channel/guild_channel.rs | 13 | ||||
| -rw-r--r-- | src/model/channel/message.rs | 29 | ||||
| -rw-r--r-- | src/model/channel/mod.rs | 42 | ||||
| -rw-r--r-- | src/model/channel/private_channel.rs | 8 | ||||
| -rw-r--r-- | src/model/channel/reaction.rs | 3 | ||||
| -rw-r--r-- | src/model/event.rs | 57 | ||||
| -rw-r--r-- | src/model/gateway.rs | 24 | ||||
| -rw-r--r-- | src/model/guild/audit_log.rs | 2 | ||||
| -rw-r--r-- | src/model/guild/member.rs | 33 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 79 | ||||
| -rw-r--r-- | src/model/guild/partial_guild.rs | 12 | ||||
| -rw-r--r-- | src/model/guild/role.rs | 5 | ||||
| -rw-r--r-- | src/model/misc.rs | 24 | ||||
| -rw-r--r-- | src/model/user.rs | 22 | ||||
| -rw-r--r-- | src/model/utils.rs | 11 | ||||
| -rw-r--r-- | src/model/webhook.rs | 5 |
18 files changed, 241 insertions, 151 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index 1c7eb46..d8ccc71 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -306,9 +306,11 @@ impl ChannelId { None => return None, } { Guild(channel) => channel.read().unwrap().name().to_string(), - Group(channel) => match channel.read().unwrap().name() { - Cow::Borrowed(name) => name.to_string(), - Cow::Owned(name) => name, + Group(channel) => { + match channel.read().unwrap().name() { + Cow::Borrowed(name) => name.to_string(), + Cow::Owned(name) => name, + } }, Private(channel) => channel.read().unwrap().name(), }) diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs index 11d6162..7007ad6 100644 --- a/src/model/channel/group.rs +++ b/src/model/channel/group.rs @@ -123,8 +123,11 @@ impl Group { reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - self.channel_id - .delete_reaction(message_id, user_id, reaction_type) + self.channel_id.delete_reaction( + message_id, + user_id, + reaction_type, + ) } /// Edits a [`Message`] in the channel given its Id. @@ -242,8 +245,12 @@ impl Group { after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.channel_id - .reaction_users(message_id, reaction_type, limit, after) + self.channel_id.reaction_users( + message_id, + reaction_type, + limit, + after, + ) } /// Removes a recipient from the group. If the recipient is already not in diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 5706fa6..3fadd72 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -311,7 +311,10 @@ impl GuildChannel { } let mut map = Map::new(); - map.insert("name".to_owned(), Value::String(self.name.clone())); + map.insert( + "name".to_owned(), + Value::String(self.name.clone()), + ); map.insert( "position".to_owned(), Value::Number(Number::from(self.position)), @@ -540,8 +543,12 @@ impl GuildChannel { after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.id - .reaction_users(message_id, reaction_type, limit, after) + self.id.reaction_users( + message_id, + reaction_type, + limit, + after, + ) } /// Sends a message with just the given message content in the channel. diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 6fdab2a..fb8fbaa 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -290,9 +290,10 @@ impl Message { } // And finally replace everyone and here mentions. - result - .replace("@everyone", "@\u{200B}everyone") - .replace("@here", "@\u{200B}here") + result.replace("@everyone", "@\u{200B}everyone").replace( + "@here", + "@\u{200B}here", + ) } /// Gets the list of [`User`]s who have reacted to a [`Message`] with a @@ -318,8 +319,12 @@ impl Message { after: Option<U>) -> Result<Vec<User>> where R: Into<ReactionType>, U: Into<UserId> { - self.channel_id - .reaction_users(self.id, reaction_type, limit, after) + self.channel_id.reaction_users( + self.id, + reaction_type, + limit, + after, + ) } /// Returns the associated `Guild` for the message if one is in the cache. @@ -332,8 +337,9 @@ impl Message { /// [`guild_id`]: #method.guild_id #[cfg(feature = "cache")] pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> { - self.guild_id() - .and_then(|guild_id| CACHE.read().unwrap().guild(guild_id)) + self.guild_id().and_then(|guild_id| { + CACHE.read().unwrap().guild(guild_id) + }) } /// Retrieves the Id of the guild that the message was sent in, if sent in @@ -353,7 +359,8 @@ impl Message { #[cfg(feature = "cache")] pub fn is_private(&self) -> bool { match CACHE.read().unwrap().channel(self.channel_id) { - Some(Channel::Group(_)) | Some(Channel::Private(_)) => true, + Some(Channel::Group(_)) | + Some(Channel::Private(_)) => true, _ => false, } } @@ -370,11 +377,7 @@ impl Message { let count = content.chars().count() as i64; let diff = count - (constants::MESSAGE_CODE_LIMIT as i64); - if diff > 0 { - Some(diff as u64) - } else { - None - } + if diff > 0 { Some(diff as u64) } else { None } } /// Pins this message to its channel. diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index cbe6085..626f466 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -117,8 +117,11 @@ impl Channel { reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - self.id() - .delete_reaction(message_id, user_id, reaction_type) + self.id().delete_reaction( + message_id, + user_id, + reaction_type, + ) } /// Edits a [`Message`] in the channel given its Id. @@ -156,7 +159,8 @@ impl Channel { pub fn is_nsfw(&self) -> bool { match *self { Channel::Guild(ref channel) => channel.read().unwrap().is_nsfw(), - Channel::Group(_) | Channel::Private(_) => false, + Channel::Group(_) | + Channel::Private(_) => false, } } @@ -216,8 +220,12 @@ impl Channel { after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.id() - .reaction_users(message_id, reaction_type, limit, after) + self.id().reaction_users( + message_id, + reaction_type, + limit, + after, + ) } /// Retrieves the Id of the inner [`Group`], [`GuildChannel`], or @@ -318,15 +326,21 @@ impl<'de> Deserialize<'de> for Channel { }; match kind { - 0 | 2 => serde_json::from_value::<GuildChannel>(Value::Object(v)) - .map(|x| Channel::Guild(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom), - 1 => serde_json::from_value::<PrivateChannel>(Value::Object(v)) - .map(|x| Channel::Private(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom), - 3 => serde_json::from_value::<Group>(Value::Object(v)) - .map(|x| Channel::Group(Arc::new(RwLock::new(x)))) - .map_err(DeError::custom), + 0 | 2 => { + serde_json::from_value::<GuildChannel>(Value::Object(v)) + .map(|x| Channel::Guild(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom) + }, + 1 => { + serde_json::from_value::<PrivateChannel>(Value::Object(v)) + .map(|x| Channel::Private(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom) + }, + 3 => { + serde_json::from_value::<Group>(Value::Object(v)) + .map(|x| Channel::Group(Arc::new(RwLock::new(x)))) + .map_err(DeError::custom) + }, _ => Err(DeError::custom("Unknown channel type")), } } diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index 277c6a1..30dc01d 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -191,8 +191,12 @@ impl PrivateChannel { after: Option<U>) -> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> { - self.id - .reaction_users(message_id, reaction_type, limit, after) + self.id.reaction_users( + message_id, + reaction_type, + limit, + after, + ) } /// Pins a [`Message`] to the channel. diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs index ac522a0..8922182 100644 --- a/src/model/channel/reaction.rs +++ b/src/model/channel/reaction.rs @@ -46,7 +46,8 @@ impl Reaction { /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html /// [permissions]: permissions pub fn delete(&self) -> Result<()> { - let user_id = feature_cache! {{ + let user_id = + feature_cache! {{ let user = if self.user_id == CACHE.read().unwrap().user.id { None } else { diff --git a/src/model/event.rs b/src/model/event.rs index 4178847..22cf649 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -153,8 +153,9 @@ impl<'de> Deserialize<'de> for GuildMemberAddEvent { Ok(GuildMemberAddEvent { guild_id: guild_id, - member: Member::deserialize(Value::Object(map)) - .map_err(DeError::custom)?, + member: Member::deserialize(Value::Object(map)).map_err( + DeError::custom, + )?, }) } } @@ -188,8 +189,9 @@ impl<'de> Deserialize<'de> for GuildMembersChunkEvent { .and_then(|v| GuildId::deserialize(v.clone())) .map_err(DeError::custom)?; - let mut members = map.remove("members") - .ok_or_else(|| DeError::custom("missing member chunk members"))?; + let mut members = map.remove("members").ok_or_else(|| { + DeError::custom("missing member chunk members") + })?; if let Some(members) = members.as_array_mut() { let num = Value::Number(Number::from(guild_id.0)); @@ -305,17 +307,24 @@ impl<'de> Deserialize<'de> for PresenceUpdateEvent { let mut map = JsonMap::deserialize(deserializer)?; let guild_id = match map.remove("guild_id") { - Some(v) => serde_json::from_value::<Option<GuildId>>(v) - .map_err(DeError::custom)?, + Some(v) => { + serde_json::from_value::<Option<GuildId>>(v).map_err( + DeError::custom, + )? + }, None => None, }; let roles = match map.remove("roles") { - Some(v) => serde_json::from_value::<Option<Vec<RoleId>>>(v) - .map_err(DeError::custom)?, + Some(v) => { + serde_json::from_value::<Option<Vec<RoleId>>>(v).map_err( + DeError::custom, + )? + }, None => None, }; - let presence = Presence::deserialize(Value::Object(map)) - .map_err(DeError::custom)?; + let presence = Presence::deserialize(Value::Object(map)).map_err( + DeError::custom, + )?; Ok(Self { guild_id: guild_id, @@ -442,8 +451,9 @@ impl<'de> Deserialize<'de> for VoiceStateUpdateEvent { Ok(VoiceStateUpdateEvent { guild_id: guild_id, - voice_state: VoiceState::deserialize(Value::Object(map)) - .map_err(DeError::custom)?, + voice_state: VoiceState::deserialize(Value::Object(map)).map_err( + DeError::custom, + )?, }) } } @@ -482,10 +492,9 @@ impl GatewayEvent { let t = map.remove("t") .ok_or_else(|| DeError::custom("expected gateway event type")) .and_then(String::deserialize)?; - let d = map.remove("d") - .ok_or_else(|| { - Error::Decode("expected gateway event d", Value::Object(map)) - })?; + let d = map.remove("d").ok_or_else(|| { + Error::Decode("expected gateway event d", Value::Object(map)) + })?; GatewayEvent::Dispatch(s, Event::decode(t, d)?) }, @@ -792,16 +801,20 @@ impl VoiceEvent { let mut map = JsonMap::deserialize(value)?; let op = match map.remove("op") { - Some(v) => VoiceOpCode::deserialize(v) - .map_err(JsonError::from) - .map_err(Error::from)?, + Some(v) => { + VoiceOpCode::deserialize(v) + .map_err(JsonError::from) + .map_err(Error::from)? + }, None => return Err(Error::Decode("expected voice event op", Value::Object(map))), }; let d = match map.remove("d") { - Some(v) => JsonMap::deserialize(v) - .map_err(JsonError::from) - .map_err(Error::from)?, + Some(v) => { + JsonMap::deserialize(v).map_err(JsonError::from).map_err( + Error::from, + )? + }, None => { return Err(Error::Decode( "expected voice gateway d", diff --git a/src/model/gateway.rs b/src/model/gateway.rs index 0c9f33e..6153abb 100644 --- a/src/model/gateway.rs +++ b/src/model/gateway.rs @@ -103,8 +103,9 @@ impl<'de> Deserialize<'de> for Game { let name = map.remove("name") .and_then(|v| String::deserialize(v).ok()) .unwrap_or_else(String::new); - let url = map.remove("url") - .and_then(|v| serde_json::from_value::<String>(v).ok()); + let url = map.remove("url").and_then(|v| { + serde_json::from_value::<String>(v).ok() + }); Ok(Game { kind: kind, @@ -170,8 +171,9 @@ impl<'de> Deserialize<'de> for Presence { .map_err(DeError::custom)?; let (user_id, user) = if user_map.len() > 1 { - let user = User::deserialize(Value::Object(user_map)) - .map_err(DeError::custom)?; + let user = User::deserialize(Value::Object(user_map)).map_err( + DeError::custom, + )?; (user.id, Some(Arc::new(RwLock::new(user)))) } else { @@ -185,8 +187,11 @@ impl<'de> Deserialize<'de> for Presence { }; let game = match map.remove("game") { - Some(v) => serde_json::from_value::<Option<Game>>(v) - .map_err(DeError::custom)?, + Some(v) => { + serde_json::from_value::<Option<Game>>(v).map_err( + DeError::custom, + )? + }, None => None, }; let last_modified = match map.remove("last_modified") { @@ -194,8 +199,11 @@ impl<'de> Deserialize<'de> for Presence { None => None, }; let nick = match map.remove("nick") { - Some(v) => serde_json::from_value::<Option<String>>(v) - .map_err(DeError::custom)?, + Some(v) => { + serde_json::from_value::<Option<String>>(v).map_err( + DeError::custom, + )? + }, None => None, }; let status = map.remove("status") diff --git a/src/model/guild/audit_log.rs b/src/model/guild/audit_log.rs index 916530e..962b145 100644 --- a/src/model/guild/audit_log.rs +++ b/src/model/guild/audit_log.rs @@ -53,7 +53,7 @@ pub enum ActionMember { Prune = 21, BanAdd = 22, BanRemove = 23, - Update = 24, + Update = 24, RoleUpdate = 25, } diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs index 38033e3..819a4e9 100644 --- a/src/model/guild/member.rs +++ b/src/model/guild/member.rs @@ -168,10 +168,9 @@ 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. @@ -179,10 +178,9 @@ 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() - .map(Cow::Borrowed) - .unwrap_or_else(|| Cow::Owned(self.user.read().unwrap().name.clone())) + self.nick.as_ref().map(Cow::Borrowed).unwrap_or_else(|| { + Cow::Owned(self.user.read().unwrap().name.clone()) + }) } /// Returns the DiscordTag of a Member, taking possible nickname into account. @@ -248,12 +246,11 @@ impl Member { { let req = permissions::KICK_MEMBERS; - let has_perms = CACHE - .read() - .unwrap() - .guilds - .get(&self.guild_id) - .map(|guild| guild.read().unwrap().has_perms(req)); + let has_perms = CACHE.read().unwrap().guilds.get(&self.guild_id).map( + |guild| { + guild.read().unwrap().has_perms(req) + }, + ); if let Some(Ok(false)) = has_perms { return Err(Error::Model(ModelError::InvalidPermissions(req))); @@ -288,10 +285,10 @@ impl Member { let guild = guild.read().unwrap(); - Ok( - guild - .permissions_for(ChannelId(guild.id.0), self.user.read().unwrap().id), - ) + Ok(guild.permissions_for( + ChannelId(guild.id.0), + self.user.read().unwrap().id, + )) } /// Removes a [`Role`] from the member, editing its roles in-place if the diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index e5e997c..3fc2a86 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -125,10 +125,11 @@ pub struct Guild { impl Guild { #[cfg(feature = "cache")] /// Returns the "default" channel of the guild. - /// (This returns the first channel that can be read by the bot, if there isn't one, returns `None`) + /// (This returns the first channel that can be read by the bot, if there isn't one, + /// returns `None`) pub fn default_channel(&self) -> Option<GuildChannel> { let uid = CACHE.read().unwrap().user.id; - + for (cid, channel) in &self.channels { if self.permissions_for(*cid, uid).read_messages() { return Some(channel.read().unwrap().clone()); @@ -139,14 +140,16 @@ impl Guild { } /// Returns the guaranteed "default" channel of the guild. - /// (This returns the first channel that can be read by everyone, if there isn't one, returns `None`) - /// Note however that this is very costy if used in a server with lots of channels, members, or both. + /// (This returns the first channel that can be read by everyone, if there isn't one, + /// returns `None`) + /// Note however that this is very costy if used in a server with lots of channels, + /// members, or both. pub fn default_channel_guaranteed(&self) -> Option<GuildChannel> { for (cid, channel) in &self.channels { for memid in self.members.keys() { if self.permissions_for(*cid, *memid).read_messages() { - return Some(channel.read().unwrap().clone()); - } + return Some(channel.read().unwrap().clone()); + } } } @@ -165,7 +168,10 @@ impl Guild { None => return Err(Error::Model(ModelError::ItemMissing)), }; - let perms = self.permissions_for(default_channel.id, member.user.read().unwrap().id); + let perms = self.permissions_for( + default_channel.id, + member.user.read().unwrap().id, + ); permissions.remove(perms); Ok(permissions.is_empty()) @@ -623,9 +629,9 @@ impl Guild { /// 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. @@ -703,8 +709,10 @@ impl Guild { for (&id, member) in &self.members { match self.presences.get(&id) { - Some(presence) => if status == presence.status { - members.push(member); + Some(presence) => { + if status == presence.status { + members.push(member); + } }, None => continue, } @@ -828,8 +836,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 @@ -955,9 +963,9 @@ impl Guild { /// 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. @@ -1036,16 +1044,18 @@ impl<'de> Deserialize<'de> for Guild { fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> { let mut map = JsonMap::deserialize(deserializer)?; - let id = map.get("id") - .and_then(|x| x.as_str()) - .and_then(|x| x.parse::<u64>().ok()); + let id = map.get("id").and_then(|x| x.as_str()).and_then(|x| { + x.parse::<u64>().ok() + }); if let Some(guild_id) = id { 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)), + ); } } } @@ -1053,16 +1063,21 @@ impl<'de> Deserialize<'de> for Guild { if let Some(array) = map.get_mut("members").and_then(|x| x.as_array_mut()) { for value in array { if let Some(member) = value.as_object_mut() { - member - .insert("guild_id".to_owned(), Value::Number(Number::from(guild_id))); + member.insert( + "guild_id".to_owned(), + Value::Number(Number::from(guild_id)), + ); } } } } 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") @@ -1214,9 +1229,9 @@ pub struct GuildInfo { 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), + ) } } @@ -1236,9 +1251,9 @@ impl From<u64> for GuildContainer { 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), + ) } } diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index 88256f0..799f6b6 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -317,9 +317,9 @@ impl PartialGuild { /// 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. @@ -419,9 +419,9 @@ impl PartialGuild { /// 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. diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs index 3f74498..5956113 100644 --- a/src/model/guild/role.rs +++ b/src/model/guild/role.rs @@ -93,8 +93,9 @@ impl Role { /// [Manage Roles]: permissions/constant.MANAGE_ROLES.html #[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. diff --git a/src/model/misc.rs b/src/model/misc.rs index d2c17c5..9420968 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -58,9 +58,11 @@ impl FromStr for User { fn from_str(s: &str) -> StdResult<Self, ()> { match utils::parse_username(s) { - Some(x) => match UserId(x as u64).find() { - Some(user) => Ok(user.read().unwrap().clone()), - _ => Err(()), + Some(x) => { + match UserId(x as u64).find() { + Some(user) => Ok(user.read().unwrap().clone()), + _ => Err(()), + } }, _ => Err(()), } @@ -82,9 +84,11 @@ impl FromStr for Role { fn from_str(s: &str) -> StdResult<Self, ()> { match utils::parse_role(s) { - Some(x) => match RoleId(x).find() { - Some(user) => Ok(user), - _ => Err(()), + Some(x) => { + match RoleId(x).find() { + Some(user) => Ok(user), + _ => Err(()), + } }, _ => Err(()), } @@ -139,9 +143,11 @@ impl FromStr for Channel { fn from_str(s: &str) -> StdResult<Self, ()> { match utils::parse_channel(s) { - Some(x) => match ChannelId(x).find() { - Some(channel) => Ok(channel), - _ => Err(()), + Some(x) => { + match ChannelId(x).find() { + Some(channel) => Ok(channel), + _ => Err(()), + } }, _ => Err(()), } diff --git a/src/model/user.rs b/src/model/user.rs index 16d5a06..7d26fd4 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -88,7 +88,10 @@ impl CurrentUser { pub fn edit<F>(&mut self, f: F) -> Result<()> where F: FnOnce(EditProfile) -> EditProfile { let mut map = Map::new(); - map.insert("username".to_owned(), Value::String(self.name.clone())); + map.insert( + "username".to_owned(), + Value::String(self.name.clone()), + ); if let Some(email) = self.email.as_ref() { map.insert("email".to_owned(), Value::String(email.clone())); @@ -113,8 +116,9 @@ impl CurrentUser { /// [`avatar_url`]: #method.avatar_url /// [`default_avatar_url`]: #method.default_avatar_url pub fn face(&self) -> String { - self.avatar_url() - .unwrap_or_else(|| self.default_avatar_url()) + self.avatar_url().unwrap_or_else( + || self.default_avatar_url(), + ) } /// Gets a list of guilds that the current user is in. @@ -487,7 +491,8 @@ impl User { return Err(Error::Model(ModelError::MessagingBot)); } - let private_channel_id = feature_cache! {{ + let private_channel_id = + feature_cache! {{ let finding = { let cache = CACHE.read().unwrap(); @@ -554,8 +559,9 @@ impl User { /// [`avatar_url`]: #method.avatar_url /// [`default_avatar_url`]: #method.default_avatar_url pub fn face(&self) -> String { - self.avatar_url() - .unwrap_or_else(|| self.default_avatar_url()) + self.avatar_url().unwrap_or_else( + || self.default_avatar_url(), + ) } /// Check if a user has a [`Role`]. This will retrieve the [`Guild`] from @@ -792,7 +798,9 @@ fn default_avatar_url(discriminator: u16) -> String { #[cfg(feature = "model")] fn static_avatar_url(user_id: UserId, hash: Option<&String>) -> Option<String> { - hash.map(|hash| cdn!("/avatars/{}/{}.webp?size=1024", user_id, hash)) + hash.map( + |hash| cdn!("/avatars/{}/{}.webp?size=1024", user_id, hash), + ) } #[cfg(feature = "model")] diff --git a/src/model/utils.rs b/src/model/utils.rs index e793df2..9fed660 100644 --- a/src/model/utils.rs +++ b/src/model/utils.rs @@ -156,7 +156,8 @@ pub fn user_has_perms(channel_id: ChannelId, mut permissions: Permissions) -> Re let guild_id = match channel { Channel::Guild(channel) => channel.read().unwrap().guild_id, - Channel::Group(_) | Channel::Private(_) => { + Channel::Group(_) | + Channel::Private(_) => { // Both users in DMs, and all users in groups, will have the same // permissions. // @@ -175,10 +176,10 @@ pub fn user_has_perms(channel_id: ChannelId, mut permissions: Permissions) -> Re None => return Err(Error::Model(ModelError::ItemMissing)), }; - let perms = guild - .read() - .unwrap() - .permissions_for(channel_id, current_user.id); + let perms = guild.read().unwrap().permissions_for( + channel_id, + current_user.id, + ); permissions.remove(perms); diff --git a/src/model/webhook.rs b/src/model/webhook.rs index 5e10d90..39099e0 100644 --- a/src/model/webhook.rs +++ b/src/model/webhook.rs @@ -118,7 +118,10 @@ impl Webhook { } if let Some(name) = name { - map.insert("name".to_owned(), Value::String(name.to_owned())); + map.insert( + "name".to_owned(), + Value::String(name.to_owned()), + ); } match http::edit_webhook_with_token(self.id.0, &self.token, &map) { |