aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-10-24 18:05:25 +0200
committeracdenisSK <[email protected]>2017-10-24 18:22:30 +0200
commit292cedaa3462f7532efda98722354afa8e213b6a (patch)
tree6205b1c47d79479b17f6591612d763ef37fe0db6 /src/model
parentFix User::has_role (diff)
downloadserenity-292cedaa3462f7532efda98722354afa8e213b6a.tar.xz
serenity-292cedaa3462f7532efda98722354afa8e213b6a.zip
Fall back to `str::parse` if `parse_username` fails
Diffstat (limited to 'src/model')
-rw-r--r--src/model/misc.rs7
1 files changed, 4 insertions, 3 deletions
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<Self, Self::Err> {
- utils::parse_username(s)
- .ok_or_else(|| UserIdParseError::InvalidFormat)
- .map(UserId)
+ Ok(match utils::parse_username(s) {
+ Some(id) => UserId(id),
+ None => s.parse::<u64>().map(UserId).map_err(|_| UserIdParseError::InvalidFormat)?,
+ })
}
}