pub struct ArtistId<'a>(/* private fields */);
Expand description

ID of type Type::Artist. 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> ArtistId<'a>

source

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).

source

pub unsafe fn from_id_unchecked<S>(id: S) -> Self
where S: Into<Cow<'a, str>>,

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.

source

pub fn from_id<S>(id: S) -> Result<Self, IdError>
where S: Into<Cow<'a, str>>,

Parse Spotify ID from string slice.

A valid Spotify object id must be a non-empty string with valid characters.

§Errors
  • IdError::InvalidId - if id contains invalid characters.
source

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 - if uri is not started with spotify: or spotify/,
  • IdError::InvalidType - if type part of an uri is not a valid Spotify type T,
  • IdError::InvalidId - if id part of an uri is 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.

source

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 - if id_or_uri is an URI, and it’s type part is not equal to T,
  • IdError::InvalidId - either if id_or_uri is an URI with invalid id part, or it’s an invalid id (id is invalid if it contains valid characters),
  • IdError::InvalidFormat - if id_or_uri is 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.

source

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.

source

pub fn into_static(self) -> ArtistId<'static>

An ID is a Cow after all, so this will switch to the its owned version, which has a 'static lifetime.

source

pub fn clone_static(&self) -> ArtistId<'static>

Similar to Self::into_static, but without consuming the original ID.

Trait Implementations§

source§

impl Borrow<str> for ArtistId<'_>

Ids may be borrowed as str the same way Box<T> may be borrowed as T or String as str

source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
source§

impl<'a> Clone for ArtistId<'a>

source§

fn clone(&self) -> ArtistId<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for ArtistId<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for ArtistId<'static>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for ArtistId<'_>

Displaying the ID shows its URI

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> From<ArtistId<'a>> for PlayContextId<'a>

source§

fn from(v: ArtistId<'a>) -> PlayContextId<'a>

Converts to this type from the input type.
source§

impl<'a> Hash for ArtistId<'a>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Id for ArtistId<'_>

source§

fn id(&self) -> &str

Returns the inner Spotify object ID, which is guaranteed to be valid for its type.
source§

fn _type(&self) -> Type

The type of the ID, as a function.
source§

fn uri(&self) -> String

Returns a Spotify object URI in a well-known format: spotify:type:id. Read more
source§

fn url(&self) -> String

Returns a full Spotify object URL that can be opened in a browser. Read more
source§

impl<'a> PartialEq for ArtistId<'a>

source§

fn eq(&self, other: &ArtistId<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Serialize for ArtistId<'a>

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'a> TryInto<ArtistId<'a>> for PlayContextId<'a>

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_into( self ) -> Result<ArtistId<'a>, <Self as TryInto<ArtistId<'a>>>::Error>

Performs the conversion.
source§

impl<'a> Eq for ArtistId<'a>

source§

impl<'a> StructuralPartialEq for ArtistId<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ArtistId<'a>

§

impl<'a> RefUnwindSafe for ArtistId<'a>

§

impl<'a> Send for ArtistId<'a>

§

impl<'a> Sync for ArtistId<'a>

§

impl<'a> Unpin for ArtistId<'a>

§

impl<'a> UnwindSafe for ArtistId<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,