aboutsummaryrefslogtreecommitdiff
path: root/src/model/id.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-24 14:30:22 -0800
committerAustin Hellyer <[email protected]>2016-11-24 14:30:22 -0800
commit6331fb5f2de580d9ba8c6de00c98032e4db5d984 (patch)
tree38eb7e6dd56eb175bdac0d9202613dfd42558777 /src/model/id.rs
parentRename guild structs to Guild and PartialGuild (diff)
downloadserenity-6331fb5f2de580d9ba8c6de00c98032e4db5d984.tar.xz
serenity-6331fb5f2de580d9ba8c6de00c98032e4db5d984.zip
Allow compiling with only either cache or methods
Some of the methods relied on the cache being present. Now, these methods only conditionally require the cache to be compiled and present. The cache was mainly used for checking if the current user had permission to perform operations.
Diffstat (limited to 'src/model/id.rs')
-rw-r--r--src/model/id.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/model/id.rs b/src/model/id.rs
index 9c9cb4d..d29fa2a 100644
--- a/src/model/id.rs
+++ b/src/model/id.rs
@@ -1,13 +1,15 @@
use super::*;
+#[cfg(all(feature = "cache", feature = "methods"))]
+use ::client::CACHE;
#[cfg(feature = "methods")]
-use ::client::{CACHE, http};
+use ::client::http;
#[cfg(feature = "methods")]
use ::internal::prelude::*;
impl ChannelId {
/// Search the cache for the channel with the Id.
- #[cfg(feature="methods")]
+ #[cfg(all(feature = "cache", feature = "methods"))]
pub fn find(&self) -> Option<Channel> {
CACHE.read().unwrap().get_channel(*self)
}
@@ -16,9 +18,11 @@ impl ChannelId {
/// requested over REST.
#[cfg(feature="methods")]
pub fn get(&self) -> Result<Channel> {
- if let Some(channel) = CACHE.read().unwrap().get_channel(*self) {
- return Ok(channel.clone());
- }
+ feature_cache_enabled! {{
+ if let Some(channel) = CACHE.read().unwrap().get_channel(*self) {
+ return Ok(channel.clone());
+ }
+ }}
http::get_channel(self.0)
}
@@ -75,7 +79,7 @@ impl From<Emoji> for EmojiId {
impl GuildId {
/// Search the cache for the guild.
- #[cfg(feature="methods")]
+ #[cfg(all(feature = "cache", feature="methods"))]
pub fn find(&self) -> Option<Guild> {
CACHE.read().unwrap().get_guild(*self).cloned()
}
@@ -161,7 +165,7 @@ impl From<Role> for RoleId {
impl RoleId {
/// Search the cache for the role.
- #[cfg(feature="methods")]
+ #[cfg(all(feature = "cache", feature = "methods"))]
pub fn find(&self) -> Option<Role> {
CACHE.read()
.unwrap()