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/misc.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/misc.rs')
| -rw-r--r-- | src/model/misc.rs | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/src/model/misc.rs b/src/model/misc.rs index d54a046..0584018 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -3,15 +3,15 @@ use internal::RwLockExt; #[cfg(all(feature = "model", feature = "utils"))] use std::result::Result as StdResult; -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "model", feature = "utils"))] use std::error::Error as StdError; #[cfg(all(feature = "model", feature = "utils"))] use std::str::FromStr; #[cfg(all(feature = "model", feature = "utils"))] use std::fmt; -#[cfg(all(feature = "cache", feature = "utils"))] -use std; -#[cfg(any(all(feature = "cache", feature = "utils"), all(feature = "model", feature = "utils")))] +#[cfg(all(feature = "model", feature = "utils"))] +use std::error::Error; +#[cfg(all(feature = "model", any(feature = "cache", feature = "utils")))] use utils; /// Allows something - such as a channel or role - to be mentioned in a message. @@ -60,20 +60,19 @@ impl Mentionable for User { fn mention(&self) -> String { format!("<@{}>", self.id.0) } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "model", feature = "utils"))] #[derive(Debug)] pub enum UserParseError { InvalidUsername, - Rest(Box<std::error::Error>), + Rest(Box<Error>), } - #[cfg(all(feature = "model", feature = "utils"))] impl fmt::Display for UserParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "model", feature = "utils"))] impl StdError for UserParseError { fn description(&self) -> &str { use self::UserParseError::*; @@ -85,26 +84,24 @@ impl StdError for UserParseError { } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "model", feature = "utils"))] impl FromStr for User { type Err = UserParseError; fn from_str(s: &str) -> StdResult<Self, Self::Err> { match utils::parse_username(s) { - Some(x) => { - UserId(x as u64).get().map_err( - |e| UserParseError::Rest(Box::new(e)), - ) - }, + Some(x) => UserId(x as u64) + .get() + .map_err(|e| UserParseError::Rest(Box::new(e))), _ => Err(UserParseError::InvalidUsername), } } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "model", feature = "utils"))] #[derive(Debug)] pub enum UserIdParseError { - NotPresentInCache, + InvalidFormat, } #[cfg(all(feature = "model", feature = "utils"))] @@ -112,13 +109,13 @@ impl fmt::Display for UserIdParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "model", feature = "utils"))] impl StdError for UserIdParseError { fn description(&self) -> &str { use self::UserIdParseError::*; match *self { - NotPresentInCache => "not present in cache", + InvalidFormat => "invalid user id format", } } } @@ -129,24 +126,24 @@ impl FromStr for UserId { fn from_str(s: &str) -> StdResult<Self, Self::Err> { utils::parse_username(s) - .ok_or_else(|| UserIdParseError::NotPresentInCache) + .ok_or_else(|| UserIdParseError::InvalidFormat) .map(UserId) } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "cache", feature = "model", feature = "utils"))] #[derive(Debug)] pub enum RoleParseError { NotPresentInCache, InvalidRole, } -#[cfg(all(feature = "model", feature = "utils"))] +#[cfg(all(feature = "cache", feature = "model", feature = "utils"))] impl fmt::Display for RoleParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "cache", feature = "model", feature = "utils"))] impl StdError for RoleParseError { fn description(&self) -> &str { use self::RoleParseError::*; @@ -158,24 +155,22 @@ impl StdError for RoleParseError { } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "cache", feature = "model", feature = "utils"))] impl FromStr for Role { type Err = RoleParseError; fn from_str(s: &str) -> StdResult<Self, Self::Err> { match utils::parse_role(s) { - Some(x) => { - match RoleId(x).find() { - Some(user) => Ok(user), - _ => Err(RoleParseError::NotPresentInCache), - } + Some(x) => match RoleId(x).find() { + Some(user) => Ok(user), + _ => Err(RoleParseError::NotPresentInCache), }, _ => Err(RoleParseError::InvalidRole), } } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "model", feature = "utils"))] #[derive(Debug)] pub enum RoleIdParseError { NotPresentInCache, @@ -186,7 +181,7 @@ impl fmt::Display for RoleIdParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) } } -#[cfg(all(feature = "cache", feature = "utils"))] +#[cfg(all(feature = "model", feature = "utils"))] impl StdError for RoleIdParseError { fn description(&self) -> &str { use self::RoleIdParseError::*; |