From 292cedaa3462f7532efda98722354afa8e213b6a Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Tue, 24 Oct 2017 18:05:25 +0200 Subject: Fall back to `str::parse` if `parse_username` fails --- src/model/misc.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/model/misc.rs b/src/model/misc.rs index af49a76..625e202 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -125,9 +125,10 @@ impl FromStr for UserId { type Err = UserIdParseError; fn from_str(s: &str) -> StdResult { - utils::parse_username(s) - .ok_or_else(|| UserIdParseError::InvalidFormat) - .map(UserId) + Ok(match utils::parse_username(s) { + Some(id) => UserId(id), + None => s.parse::().map(UserId).map_err(|_| UserIdParseError::InvalidFormat)?, + }) } } -- cgit v1.2.3