Struct spotify_client::prelude::TrackId
source · 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) -> TrackId<'a>
pub unsafe fn from_id_unchecked<S>(id: S) -> TrackId<'a>
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<TrackId<'a>, IdError>
pub fn from_id<S>(id: S) -> Result<TrackId<'a>, 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<TrackId<'a>, IdError>
pub fn from_uri(uri: &'a str) -> Result<TrackId<'a>, 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<TrackId<'a>, IdError>
pub fn from_id_or_uri(id_or_uri: &'a str) -> Result<TrackId<'a>, 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) -> TrackId<'a>
pub fn as_ref(&'a self) -> TrackId<'a>
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<'_>
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
source§impl<'de> Deserialize<'de> for TrackId<'static>
impl<'de> Deserialize<'de> for TrackId<'static>
source§fn deserialize<D>(
deserializer: D
) -> Result<TrackId<'static>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<TrackId<'static>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl<'a> From<TrackId<'a>> for PlayableId<'a>
impl<'a> From<TrackId<'a>> for PlayableId<'a>
source§fn from(v: TrackId<'a>) -> PlayableId<'a>
fn from(v: TrackId<'a>) -> PlayableId<'a>
source§impl Id for TrackId<'_>
impl Id for TrackId<'_>
source§impl<'a> PartialEq for TrackId<'a>
impl<'a> PartialEq for TrackId<'a>
source§impl<'a> Serialize for TrackId<'a>
impl<'a> Serialize for TrackId<'a>
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl<'a> TryInto<TrackId<'a>> for PlayableId<'a>
impl<'a> TryInto<TrackId<'a>> for PlayableId<'a>
impl<'a> Eq for TrackId<'a>
impl<'a> StructuralPartialEq for TrackId<'a>
Auto Trait Implementations§
impl<'a> Freeze for TrackId<'a>
impl<'a> RefUnwindSafe for TrackId<'a>
impl<'a> Send for TrackId<'a>
impl<'a> Sync for TrackId<'a>
impl<'a> Unpin for TrackId<'a>
impl<'a> UnwindSafe for TrackId<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more