From 5d4301bbd2aaa4abe47fbbc2a7a2853ba9b728f2 Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Tue, 24 Oct 2017 18:12:21 +0200 Subject: Add a fallback to `RoleId::from_str` as well --- src/model/misc.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') 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 { - Ok(match utils::parse_username(s) + Ok(match utils::parse_username(s) { Some(id) => UserId(id), - None => s.parse::().map(UserId).map_err(|_| UserIdParseError::InvalidFormat) + None => s.parse::().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 { - utils::parse_role(s) - .ok_or_else(|| RoleIdParseError::NotPresentInCache) - .map(RoleId) + Ok(match utils::parse_role(s) { + Some(id) => RoleId(id), + None => s.parse::().map(RoleId).map_err(|_| RoleIdParseError::InvalidFormat)?, + }) } } -- cgit v1.2.3