diff options
| author | acdenisSK <[email protected]> | 2017-09-09 10:53:44 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-09-09 10:56:29 +0200 |
| commit | 4be6b9d5008ff8bb3d1fdddff5647a6bb307513c (patch) | |
| tree | 516b811875ae4cb2b98c308aabb69bc6e7a94fd2 /src/cache/mod.rs | |
| parent | Change order to avoid subtraction overflow error (#160) (diff) | |
| download | serenity-4be6b9d5008ff8bb3d1fdddff5647a6bb307513c.tar.xz serenity-4be6b9d5008ff8bb3d1fdddff5647a6bb307513c.zip | |
Implement categories
Diffstat (limited to 'src/cache/mod.rs')
| -rw-r--r-- | src/cache/mod.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cache/mod.rs b/src/cache/mod.rs index b92e72f..3a53262 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -76,6 +76,8 @@ pub struct Cache { /// [`Event::GuildUnavailable`]: ../model/event/struct.GuildUnavailableEvent.html /// [`Guild`]: ../model/struct.Guild.html pub channels: HashMap<ChannelId, Arc<RwLock<GuildChannel>>>, + /// A map of channel categories. + pub categories: HashMap<ChannelId, Arc<RwLock<ChannelCategory>>>, /// A map of the groups that the current user is in. /// /// For bot users this will always be empty, except for in [special cases]. @@ -593,6 +595,11 @@ impl Cache { self.users.get(&user_id.into()).cloned() } + #[inline] + pub fn categories<C: Into<ChannelId>>(&self, channel_id: C) -> Option<Arc<RwLock<ChannelCategory>>> { + self.categories.get(&channel_id.into()).cloned() + } + fn update_user_entry(&mut self, user: &User) { match self.users.entry(user.id) { Entry::Vacant(e) => { @@ -609,6 +616,7 @@ impl Default for Cache { fn default() -> Cache { Cache { channels: HashMap::default(), + categories: HashMap::default(), groups: HashMap::with_capacity(128), guilds: HashMap::default(), notes: HashMap::default(), |