Skip to content

Commit

Permalink
better fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kstep committed Mar 7, 2021
1 parent 11fc5b0 commit 141e6e0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/model/idtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,15 @@ impl<T: IdType> Id<T> {
/// - `IdError::InvalidFormat` - if it can't be splitted into type and
/// id parts.
pub fn from_uri<'a, 'b: 'a>(uri: &'b str) -> Result<&'a Id<T>, IdError> {
let rest = uri.strip_prefix("spotify").ok_or(IdError::InvalidPrefix)?;
let (sep, rest) = rest.split_at(1);
if sep != "/" && sep != ":" {
return Err(IdError::InvalidPrefix);
}
let mut chars = uri
.strip_prefix("spotify")
.ok_or(IdError::InvalidPrefix)?
.chars();
let sep = match chars.next() {
Some(ch) if ch == '/' || ch == ':' => ch,
_ => return Err(IdError::InvalidPrefix),
};
let rest = chars.as_str();

let (tpe, id) = rest
.rfind(sep)
Expand Down

0 comments on commit 141e6e0

Please sign in to comment.