diff options
| author | acdenisSK <[email protected]> | 2017-10-24 18:12:21 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-10-24 18:21:32 +0200 |
| commit | 5d4301bbd2aaa4abe47fbbc2a7a2853ba9b728f2 (patch) | |
| tree | 732faeebb0a5e5aa8a2e7392498b3f86c58e48f1 /src/model | |
| parent | Remove unwraps (diff) | |
| download | serenity-5d4301bbd2aaa4abe47fbbc2a7a2853ba9b728f2.tar.xz serenity-5d4301bbd2aaa4abe47fbbc2a7a2853ba9b728f2.zip | |
Add a fallback to `RoleId::from_str` as well
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/misc.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/model/misc.rs b/src/model/misc.rs index 3398a14..51c304d 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -125,9 +125,9 @@ impl FromStr for UserId { type Err = UserIdParseError; fn from_str(s: &str) -> StdResult<Self, Self::Err> { - Ok(match utils::parse_username(s) + Ok(match utils::parse_username(s) { Some(id) => UserId(id), - None => s.parse::<u64>().map(UserId).map_err(|_| UserIdParseError::InvalidFormat) + None => s.parse::<u64>().map(UserId).map_err(|_| UserIdParseError::InvalidFormat)?, }) } } @@ -174,7 +174,7 @@ impl FromStr for Role { #[cfg(all(feature = "model", feature = "utils"))] #[derive(Debug)] pub enum RoleIdParseError { - NotPresentInCache, + InvalidFormat, } #[cfg(all(feature = "model", feature = "utils"))] @@ -188,7 +188,7 @@ impl StdError for RoleIdParseError { use self::RoleIdParseError::*; match *self { - NotPresentInCache => "not present in cache", + InvalidFormat => "invalid role id format", } } } @@ -198,9 +198,10 @@ impl FromStr for RoleId { type Err = RoleIdParseError; fn from_str(s: &str) -> StdResult<Self, Self::Err> { - utils::parse_role(s) - .ok_or_else(|| RoleIdParseError::NotPresentInCache) - .map(RoleId) + Ok(match utils::parse_role(s) { + Some(id) => RoleId(id), + None => s.parse::<u64>().map(RoleId).map_err(|_| RoleIdParseError::InvalidFormat)?, + }) } } |