Skip to content

Commit

Permalink
Fall back to str::parse if parse_username fails
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis committed Oct 24, 2017
1 parent d3015a0 commit 292ceda
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/model/misc.rs
Expand Up @@ -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)?,
})
}
}

Expand Down

0 comments on commit 292ceda

Please sign in to comment.