diff options
| author | Maiddog <[email protected]> | 2017-08-24 07:45:29 -0500 |
|---|---|---|
| committer | alex <[email protected]> | 2017-08-24 14:45:29 +0200 |
| commit | 562ce49698a39d5da68d3ac58a3d8cf401aa9e42 (patch) | |
| tree | 09e24d0cda0c5f66fc3454a90fb9087958aa55cd /src/model | |
| parent | Apply rustfmt fixes (diff) | |
| download | serenity-562ce49698a39d5da68d3ac58a3d8cf401aa9e42.tar.xz serenity-562ce49698a39d5da68d3ac58a3d8cf401aa9e42.zip | |
Allow FromStr for User to use REST (#147)
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/misc.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/model/misc.rs b/src/model/misc.rs index dee915e..0d1f146 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -8,6 +8,8 @@ use std::error::Error as StdError; 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")))] use utils; @@ -59,8 +61,8 @@ impl Mentionable for User { #[cfg(all(feature = "cache", feature = "utils"))] #[derive(Debug)] pub enum UserParseError { - NotPresentInCache, InvalidUsername, + Rest(Box<std::error::Error>), } @@ -75,8 +77,8 @@ impl StdError for UserParseError { use self::UserParseError::*; match *self { - NotPresentInCache => "not present in cache", InvalidUsername => "invalid username", + Rest(_) => "could not fetch", } } } @@ -88,10 +90,9 @@ impl FromStr for User { fn from_str(s: &str) -> StdResult<Self, Self::Err> { match utils::parse_username(s) { Some(x) => { - match UserId(x as u64).find() { - Some(user) => Ok(user.read().unwrap().clone()), - _ => Err(UserParseError::NotPresentInCache), - } + UserId(x as u64).get().map_err( + |e| UserParseError::Rest(Box::new(e)), + ) }, _ => Err(UserParseError::InvalidUsername), } |