diff options
| author | Zeyla Hellyer <[email protected]> | 2017-09-18 10:47:19 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-09-18 17:48:37 -0700 |
| commit | 8e3b4d601ffb78909db859640482f7e0bb10131f (patch) | |
| tree | 16500c9274a0517a776ea707bb623d1c9947d8cf /src/model/channel/channel_id.rs | |
| parent | Apply rustfmt (diff) | |
| download | serenity-8e3b4d601ffb78909db859640482f7e0bb10131f.tar.xz serenity-8e3b4d601ffb78909db859640482f7e0bb10131f.zip | |
Fix compiles of a variety of feature combinations
This fixes compilation errors and warnings when compiling a mixture of
non-default feature targets.
Diffstat (limited to 'src/model/channel/channel_id.rs')
| -rw-r--r-- | src/model/channel/channel_id.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index aec6cf0..a8e16ef 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -8,7 +8,7 @@ use std::borrow::Cow; use std::fmt::Write as FmtWrite; #[cfg(feature = "model")] use builder::{CreateMessage, EditChannel, GetMessages}; -#[cfg(feature = "cache")] +#[cfg(all(feature = "cache", feature = "model"))] use CACHE; #[cfg(feature = "model")] use http::{self, AttachmentType}; @@ -302,17 +302,23 @@ impl ChannelId { pub fn name(&self) -> Option<String> { use self::Channel::*; - // TODO: Replace this second match with `?`. - Some(match match self.find() { - Some(c) => c, - None => return None, - } { + let finding = feature_cache! {{ + Some(self.find()) + } else { + None + }}; + + let channel = if let Some(Some(c)) = finding { + c + } else { + return None; + }; + + Some(match channel { 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, }, Category(category) => category.read().unwrap().name().to_string(), Private(channel) => channel.read().unwrap().name(), |