Struct UserId

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

ID of type Type::User. The validity of its characters is defined by the closure |_| true.

Refer to the module-level docs for more information.

Implementations§

Source§

impl<'a> UserId<'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) -> UserId<'a>
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<UserId<'a>, 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<UserId<'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 - 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<UserId<'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 - 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) -> UserId<'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.

Source

pub fn into_static(self) -> UserId<'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) -> UserId<'static>

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

Trait Implementations§

Source§

impl Borrow<str> for UserId<'_>

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 UserId<'a>

Source§

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

Returns a duplicate 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 UserId<'a>

Source§

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

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

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

Source§

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

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

impl Display for UserId<'_>

Displaying the ID shows its URI

Source§

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

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

impl<'a> Hash for UserId<'a>

Source§

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

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 UserId<'_>

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 UserId<'a>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Serialize for UserId<'a>

Source§

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

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

impl<'a> Eq for UserId<'a>

Source§

impl<'a> StructuralPartialEq for UserId<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for UserId<'a>

§

impl<'a> RefUnwindSafe for UserId<'a>

§

impl<'a> Send for UserId<'a>

§

impl<'a> Sync for UserId<'a>

§

impl<'a> Unpin for UserId<'a>

§

impl<'a> UnwindSafe for UserId<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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§

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>,

Source§

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>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,