aboutsummaryrefslogtreecommitdiff
path: root/src/cache
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-10-02 22:29:10 +0200
committeracdenisSK <[email protected]>2017-10-02 22:29:10 +0200
commit6a4e52b3fac7d2e96e3a1a67901fbdd4721fb249 (patch)
treeae9ad7d7cb73d4ece6a199796af5975545071493 /src/cache
parent`to_owned` -> `to_string` (diff)
downloadserenity-6a4e52b3fac7d2e96e3a1a67901fbdd4721fb249.tar.xz
serenity-6a4e52b3fac7d2e96e3a1a67901fbdd4721fb249.zip
Use the de-generification trick.
Fixes #168
Diffstat (limited to 'src/cache')
-rw-r--r--src/cache/mod.rs52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/cache/mod.rs b/src/cache/mod.rs
index 2bbc9bc..def6ac4 100644
--- a/src/cache/mod.rs
+++ b/src/cache/mod.rs
@@ -298,8 +298,10 @@ impl Cache {
/// [`groups`]: #structfield.groups
/// [`private_channels`]: #structfield.private_channels
pub fn channel<C: Into<ChannelId>>(&self, id: C) -> Option<Channel> {
- let id = id.into();
+ self._channel(id.into())
+ }
+ fn _channel(&self, id: ChannelId) -> Option<Channel> {
if let Some(channel) = self.channels.get(&id) {
return Some(Channel::Guild(channel.clone()));
}
@@ -346,7 +348,11 @@ impl Cache {
/// ```
#[inline]
pub fn guild<G: Into<GuildId>>(&self, id: G) -> Option<Arc<RwLock<Guild>>> {
- self.guilds.get(&id.into()).cloned()
+ self._guild(id.into())
+ }
+
+ fn _guild(&self, id: GuildId) -> Option<Arc<RwLock<Guild>>> {
+ self.guilds.get(&id).cloned()
}
/// Retrieves a reference to a [`Guild`]'s channel. Unlike [`channel`],
@@ -395,7 +401,11 @@ impl Cache {
/// [`channel`]: #method.channel
#[inline]
pub fn guild_channel<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<GuildChannel>>> {
- self.channels.get(&id.into()).cloned()
+ self._guild_channel(id.into())
+ }
+
+ fn _guild_channel(&self, id: ChannelId) -> Option<Arc<RwLock<GuildChannel>>> {
+ self.channels.get(&id).cloned()
}
/// Retrieves a reference to a [`Group`] from the cache based on the given
@@ -431,7 +441,11 @@ impl Cache {
/// ```
#[inline]
pub fn group<C: Into<ChannelId>>(&self, id: C) -> Option<Arc<RwLock<Group>>> {
- self.groups.get(&id.into()).cloned()
+ self._group(id.into())
+ }
+
+ fn _group(&self, id: ChannelId) -> Option<Arc<RwLock<Group>>> {
+ self.groups.get(&id).cloned()
}
/// Retrieves a [`Guild`]'s member from the cache based on the guild's and
@@ -481,6 +495,10 @@ impl Cache {
/// [`members`]: ../model/struct.Guild.html#structfield.members
pub fn member<G, U>(&self, guild_id: G, user_id: U) -> Option<Member>
where G: Into<GuildId>, U: Into<UserId> {
+ self._member(guild_id.into(), user_id.into())
+ }
+
+ fn _member(&self, guild_id: GuildId, user_id: UserId) -> Option<Member> {
self.guilds.get(&guild_id.into()).and_then(|guild| {
guild.read().unwrap().members.get(&user_id.into()).cloned()
})
@@ -518,7 +536,11 @@ impl Cache {
pub fn private_channel<C: Into<ChannelId>>(&self,
channel_id: C)
-> Option<Arc<RwLock<PrivateChannel>>> {
- self.private_channels.get(&channel_id.into()).cloned()
+ self._private_channel(channel_id.into())
+ }
+
+ fn _private_channel(&self, channel_id: ChannelId) -> Option<Arc<RwLock<PrivateChannel>>> {
+ self.private_channels.get(&channel_id).cloned()
}
/// Retrieves a [`Guild`]'s role by their Ids.
@@ -553,9 +575,13 @@ impl Cache {
/// ```
pub fn role<G, R>(&self, guild_id: G, role_id: R) -> Option<Role>
where G: Into<GuildId>, R: Into<RoleId> {
+ self._role(guild_id.into(), role_id.into())
+ }
+
+ fn _role(&self, guild_id: GuildId, role_id: RoleId) -> Option<Role> {
self.guilds
- .get(&guild_id.into())
- .and_then(|g| g.read().unwrap().roles.get(&role_id.into()).cloned())
+ .get(&guild_id)
+ .and_then(|g| g.read().unwrap().roles.get(&role_id).cloned())
}
/// Retrieves a `User` from the cache's [`users`] map, if it exists.
@@ -590,14 +616,22 @@ impl Cache {
/// ```
#[inline]
pub fn user<U: Into<UserId>>(&self, user_id: U) -> Option<Arc<RwLock<User>>> {
- self.users.get(&user_id.into()).cloned()
+ self._user(user_id.into())
+ }
+
+ fn _user(&self, user_id: UserId) -> Option<Arc<RwLock<User>>> {
+ self.users.get(&user_id).cloned()
}
#[inline]
pub fn categories<C: Into<ChannelId>>(&self,
channel_id: C)
-> Option<Arc<RwLock<ChannelCategory>>> {
- self.categories.get(&channel_id.into()).cloned()
+ self._categories(channel_id.into())
+ }
+
+ fn _categories(&self, channel_id: ChannelId) -> Option<Arc<RwLock<ChannelCategory>>> {
+ self.categories.get(&channel_id).cloned()
}
#[cfg(feature = "client")]