diff options
| author | Zeyla Hellyer <[email protected]> | 2017-09-09 08:23:21 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-09-09 08:23:21 -0700 |
| commit | 1c138a357b37e3bd8002109cfb9a8da94a53810e (patch) | |
| tree | 3256df54f6b31e0422848ea6bcc1d35e58b27eee | |
| parent | `parent_id` -> `category_id` (diff) | |
| download | serenity-1c138a357b37e3bd8002109cfb9a8da94a53810e.tar.xz serenity-1c138a357b37e3bd8002109cfb9a8da94a53810e.zip | |
Apply rustfmt + fix tests
| -rw-r--r-- | src/cache/cache_events_impl.rs | 12 | ||||
| -rw-r--r-- | src/cache/mod.rs | 4 | ||||
| -rw-r--r-- | src/model/channel/channel_category.rs | 23 | ||||
| -rw-r--r-- | src/model/channel/guild_channel.rs | 6 | ||||
| -rw-r--r-- | src/model/channel/message.rs | 1 | ||||
| -rw-r--r-- | src/model/guild/member.rs | 7 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 2 | ||||
| -rw-r--r-- | src/model/utils.rs | 3 | ||||
| -rw-r--r-- | tests/test_channels.rs | 1 | ||||
| -rw-r--r-- | tests/test_formatters.rs | 1 |
10 files changed, 44 insertions, 16 deletions
diff --git a/src/cache/cache_events_impl.rs b/src/cache/cache_events_impl.rs index 64dbfde..e5a6f68 100644 --- a/src/cache/cache_events_impl.rs +++ b/src/cache/cache_events_impl.rs @@ -113,7 +113,9 @@ impl CacheEventsImpl for super::Cache { ch.map(Channel::Private) }, Channel::Category(ref category) => { - self.categories.insert(category.read().unwrap().id, category.clone()).map(Channel::Category) + self.categories + .insert(category.read().unwrap().id, category.clone()) + .map(Channel::Category) }, } } @@ -225,9 +227,11 @@ impl CacheEventsImpl for super::Cache { .map(|private| private.clone_from(channel)); }, Channel::Category(ref category) => { - self.categories - .get_mut(&category.read().unwrap().id) - .map(|c| c.clone_from(category)); + self.categories.get_mut(&category.read().unwrap().id).map( + |c| { + c.clone_from(category) + }, + ); }, } } diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 3a53262..88e4266 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -596,7 +596,9 @@ impl Cache { } #[inline] - pub fn categories<C: Into<ChannelId>>(&self, channel_id: C) -> Option<Arc<RwLock<ChannelCategory>>> { + pub fn categories<C: Into<ChannelId>>(&self, + channel_id: C) + -> Option<Arc<RwLock<ChannelCategory>>> { self.categories.get(&channel_id.into()).cloned() } diff --git a/src/model/channel/channel_category.rs b/src/model/channel/channel_category.rs index a0673fd..29f6b36 100644 --- a/src/model/channel/channel_category.rs +++ b/src/model/channel/channel_category.rs @@ -104,9 +104,26 @@ impl ChannelCategory { let edited = f(EditChannel(map)).0; http::edit_channel(self.id.0, &edited).map(|channel| { - let GuildChannel { id, category_id, permission_overwrites, nsfw, name, position, kind, .. } = channel; + let GuildChannel { + id, + category_id, + permission_overwrites, + nsfw, + name, + position, + kind, + .. + } = channel; - *self = ChannelCategory { id, category_id, permission_overwrites, nsfw, name, position, kind }; + *self = ChannelCategory { + id, + category_id, + permission_overwrites, + nsfw, + name, + position, + kind, + }; () }) } @@ -119,4 +136,4 @@ impl ChannelCategory { /// Returns the name of the category. pub fn name(&self) -> &str { &self.name } -}
\ No newline at end of file +} diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 8ae50a6..3e33102 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -24,13 +24,13 @@ pub struct GuildChannel { /// /// The default channel Id shares the Id of the guild and the default role. pub id: ChannelId, - /// Whether this guild channel belongs in a category. - #[serde(rename = "parent_id")] - pub category_id: Option<ChannelId>, /// The bitrate of the channel. /// /// **Note**: This is only available for voice channels. pub bitrate: Option<u64>, + /// Whether this guild channel belongs in a category. + #[serde(rename = "parent_id")] + pub category_id: Option<ChannelId>, /// The Id of the guild the channel is located in. /// /// If this matches with the [`id`], then this is the default text channel. diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 27f4e31..03aea16 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -97,6 +97,7 @@ impl Message { /// /// command!(channel_name(_ctx, msg) { /// let _ = match msg.channel() { + /// Some(Channel::Category(c)) => msg.reply(&c.read().unwrap().name), /// Some(Channel::Group(c)) => msg.reply(&c.read().unwrap().name()), /// Some(Channel::Guild(c)) => msg.reply(&c.read().unwrap().name), /// Some(Channel::Private(c)) => { diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs index d9ac230..6873dc7 100644 --- a/src/model/guild/member.rs +++ b/src/model/guild/member.rs @@ -274,8 +274,9 @@ impl Member { /// /// Returns a [`ModelError::GuildNotFound`] if the guild the member's in could not be /// found in the cache. - /// - /// And/or returns [`ModelError::ItemMissing`] if the "default channel" of the guild is not found. + /// + /// And/or returns [`ModelError::ItemMissing`] if the "default channel" of the guild is not + /// found. /// /// [`ModelError::GuildNotFound`]: enum.ModelError.html#variant.GuildNotFound /// [`ModelError::ItemMissing`]: enum.ModelError.html#variant.ItemMissing @@ -292,7 +293,7 @@ impl Member { Some(dc) => dc, None => return Err(From::from(ModelError::ItemMissing)), }; - + Ok(guild.permissions_for( default_channel.id, self.user.read().unwrap().id, diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 714cf5c..47f789e 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -207,7 +207,7 @@ impl Guild { /// [`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, options: BO) -> Result<()> { + pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, options: BO) -> Result<()> { #[cfg(feature = "cache")] { let req = permissions::BAN_MEMBERS; diff --git a/src/model/utils.rs b/src/model/utils.rs index 123f683..89d498a 100644 --- a/src/model/utils.rs +++ b/src/model/utils.rs @@ -160,7 +160,8 @@ pub fn user_has_perms(channel_id: ChannelId, mut permissions: Permissions) -> Re Channel::Group(_) | Channel::Private(_) | Channel::Category(_) => { - // Both users in DMs, and all users in groups and maybe all channels in categories will have the same + // Both users in DMs, and all users in groups and maybe all channels in categories will + // have the same // permissions. // // The only exception to this is when the current user is blocked by diff --git a/tests/test_channels.rs b/tests/test_channels.rs index dd00c3e..246243d 100644 --- a/tests/test_channels.rs +++ b/tests/test_channels.rs @@ -22,6 +22,7 @@ mod utils { GuildChannel { id: ChannelId(1), bitrate: None, + category_id: None, guild_id: GuildId(2), kind: ChannelType::Text, last_message_id: None, diff --git a/tests/test_formatters.rs b/tests/test_formatters.rs index 90ad16c..9093cee 100644 --- a/tests/test_formatters.rs +++ b/tests/test_formatters.rs @@ -19,6 +19,7 @@ fn test_mention() { let channel = Channel::Guild(Arc::new(RwLock::new(GuildChannel { bitrate: None, + category_id: None, guild_id: GuildId(1), kind: ChannelType::Text, id: ChannelId(4), |