aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaiddog <[email protected]>2017-08-24 07:45:29 -0500
committeralex <[email protected]>2017-08-24 14:45:29 +0200
commit562ce49698a39d5da68d3ac58a3d8cf401aa9e42 (patch)
tree09e24d0cda0c5f66fc3454a90fb9087958aa55cd /src
parentApply rustfmt fixes (diff)
downloadserenity-562ce49698a39d5da68d3ac58a3d8cf401aa9e42.tar.xz
serenity-562ce49698a39d5da68d3ac58a3d8cf401aa9e42.zip
Allow FromStr for User to use REST (#147)
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs3
-rw-r--r--src/model/misc.rs13
2 files changed, 9 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 230ab68..3893968 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -85,7 +85,8 @@
//! [examples]: https://github.com/zeyla/serenity/tree/master/examples
//! [gateway docs]: gateway/index.html
#![doc(html_root_url = "https://docs.rs/serenity/*")]
-#![allow(doc_markdown, inline_always, unknown_lints)]
+#![allow(unknown_lints)]
+#![allow(doc_markdown, inline_always)]
#![warn(enum_glob_use, if_not_else)]
#[macro_use]
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),
}