pub struct TrackId<'a>(/* private fields */);Expand description
ID of type Type::Track. The validity of its characters is defined by the closure |id| id.chars().all(|ch| ch.is_ascii_alphanumeric()).
Refer to the module-level docs for more information.
Implementations§
Source§impl<'a> TrackId<'a>
impl<'a> TrackId<'a>
Sourcepub fn id_is_valid(id: &str) -> bool
pub fn id_is_valid(id: &str) -> bool
Only returns true in case the given string is valid
according to that specific ID (e.g., some may require
alphanumeric characters only).
Sourcepub unsafe fn from_id_unchecked<S>(id: S) -> Self
pub unsafe fn from_id_unchecked<S>(id: S) -> Self
Initialize the ID without checking its validity.
§Safety
The string passed to this method must be made out of valid characters only; otherwise undefined behaviour may occur.
Sourcepub fn from_id<S>(id: S) -> Result<Self, IdError>
pub fn from_id<S>(id: S) -> Result<Self, IdError>
Parse Spotify ID from string slice.
A valid Spotify object id must be a non-empty string with valid characters.
§Errors
IdError::InvalidId- ifidcontains invalid characters.
Sourcepub fn from_uri(uri: &'a str) -> Result<Self, IdError>
pub fn from_uri(uri: &'a str) -> Result<Self, IdError>
Parse Spotify URI from string slice
Spotify URI must be in one of the following formats:
spotify:{type}:{id} or spotify/{type}/{id}.
Where {type} is one of artist, album, track,
playlist, user, show, or episode, and {id} is a
non-empty valid string.
Examples: spotify:album:6IcGNaXFRf5Y1jc7QsE9O2,
spotify/track/4y4VO05kYgUTo2bzbox1an.
§Errors
IdError::InvalidPrefix- ifuriis not started withspotify:orspotify/,IdError::InvalidType- if type part of anuriis not a valid Spotify typeT,IdError::InvalidId- if id part of anuriis not a valid id,IdError::InvalidFormat- if it can’t be splitted into type and id parts.
§Implementation details
Unlike Self::from_id, this method takes a &str rather
than an Into<Cow<str>>. This is because the inner Cow in
the ID would reference a slice from the given &str (i.e.,
taking the ID out of the URI). The parameter wouldn’t live
long enough when using Into<Cow<str>>, so the only
sensible choice is to just use a &str.
Sourcepub fn from_id_or_uri(id_or_uri: &'a str) -> Result<Self, IdError>
pub fn from_id_or_uri(id_or_uri: &'a str) -> Result<Self, IdError>
Parse Spotify ID or URI from string slice
Spotify URI must be in one of the following formats:
spotify:{type}:{id} or spotify/{type}/{id}.
Where {type} is one of artist, album, track,
playlist, user, show, or episode, and {id} is a
non-empty valid string. The URI must be match with the ID’s
type (Id::TYPE), otherwise IdError::InvalidType error is
returned.
Examples: spotify:album:6IcGNaXFRf5Y1jc7QsE9O2,
spotify/track/4y4VO05kYgUTo2bzbox1an.
If input string is not a valid Spotify URI (it’s not started
with spotify: or spotify/), it must be a valid Spotify
object ID, i.e. a non-empty valid string.
§Errors
IdError::InvalidType- ifid_or_uriis an URI, and it’s type part is not equal toT,IdError::InvalidId- either ifid_or_uriis an URI with invalid id part, or it’s an invalid id (id is invalid if it contains valid characters),IdError::InvalidFormat- ifid_or_uriis an URI, and it can’t be split into type and id parts.
§Implementation details
Unlike Self::from_id, this method takes a &str rather
than an Into<Cow<str>>. This is because the inner Cow in
the ID would reference a slice from the given &str (i.e.,
taking the ID out of the URI). The parameter wouldn’t live
long enough when using Into<Cow<str>>, so the only
sensible choice is to just use a &str.
Sourcepub fn as_ref(&'a self) -> Self
pub fn as_ref(&'a self) -> Self
This creates an ID with the underlying &str variant from a
reference. Useful to use an ID multiple times without having
to clone it.
Sourcepub fn into_static(self) -> TrackId<'static>
pub fn into_static(self) -> TrackId<'static>
An ID is a Cow after all, so this will switch to the its
owned version, which has a 'static lifetime.
Sourcepub fn clone_static(&self) -> TrackId<'static>
pub fn clone_static(&self) -> TrackId<'static>
Similar to Self::into_static, but without consuming the
original ID.
Trait Implementations§
Source§impl Borrow<str> for TrackId<'_>
Ids may be borrowed as str the same way Box<T> may be
borrowed as T or String as str
impl Borrow<str> for TrackId<'_>
Ids may be borrowed as str the same way Box<T> may be
borrowed as T or String as str