Client

Struct Client 

Source
pub struct Client<A: AsRef<str>, U: AsRef<str>> { /* private fields */ }
Expand description

A client for the Last.fm API.

Implementations§

Source§

impl<A: AsRef<str>, U: AsRef<str>> Client<A, U>

Source

pub fn builder() -> ClientBuilder<A, U, ((), (), (), (), ())>

Create a builder for building Client. On the builder, call .api_key(...), .username(...), .reqwest_client(...)(optional), .base_url(...)(optional), .retry_strategy(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of Client.

Source§

impl<A: AsRef<str>, U: AsRef<str>> Client<A, U>

Source

pub fn from_env(username: U) -> Client<String, U>

Creates a new Client with the given username. The API key is read from the LASTFM_API_KEY environment variable. This method is a shortcut for [ClientBuilder::from_env] but, in case of failure, it will panic rather than returning an error.

§Panics

If the environment variable is not set, this function will panic.

Source

pub fn try_from_env(username: U) -> Result<Client<String, U>, VarError>

Creates a new Client with the given username. The API key is read from the LASTFM_API_KEY environment variable. If the environment variable is not set, this function will return an error.

Source

pub async fn now_playing(&self) -> Result<Option<NowPlayingTrack>, Error>

Fetches the currently playing track for the user (if any)

Source

pub async fn all_tracks(self) -> Result<RecentTracksFetcher, Error>

Creates a new RecentTracksFetcher that can be used to fetch all of the user’s recent tracks.

Source

pub async fn recent_tracks( self, from: Option<i64>, to: Option<i64>, ) -> Result<RecentTracksFetcher, Error>

Creates a new RecentTracksFetcher that can be used to fetch the user’s recent tracks in a given time range.

The from and to parameters are Unix timestamps (in seconds).

Trait Implementations§

Source§

impl<A: Clone + AsRef<str>, U: Clone + AsRef<str>> Clone for Client<A, U>

Source§

fn clone(&self) -> Client<A, U>

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: AsRef<str>, U: AsRef<str>> Debug for Client<A, U>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A, U> Freeze for Client<A, U>
where A: Freeze, U: Freeze,

§

impl<A, U> !RefUnwindSafe for Client<A, U>

§

impl<A, U> Send for Client<A, U>
where A: Send, U: Send,

§

impl<A, U> Sync for Client<A, U>
where A: Sync, U: Sync,

§

impl<A, U> Unpin for Client<A, U>
where A: Unpin, U: Unpin,

§

impl<A, U> !UnwindSafe for Client<A, U>

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