ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder { /* private fields */ }
Expand description

Configuration builder for creating a Config instance

Implementations§

Source§

impl ConfigBuilder

Source

pub fn build_client(self) -> Result<LastFmClient>

Build a LastFmClient directly from this builder

This is equivalent to calling build().map(LastFmClient::from_config).

§Errors

Returns an error if the builder is missing required fields (e.g., API key).

Source§

impl ConfigBuilder

Source

pub fn new() -> Self

Create a new configuration builder

Source

pub fn api_key(self, key: impl Into<String>) -> Self

Set the API key

§Example
use lastfm_client::ConfigBuilder;

let builder = ConfigBuilder::new().api_key("my_api_key");
Source

pub fn from_env(self) -> Result<Self>

Load API key from environment variable

§Example
use lastfm_client::ConfigBuilder;

let builder = ConfigBuilder::new().from_env()?;
§Errors

Returns an error if the LAST_FM_API_KEY environment variable is missing.

Source

pub fn user_agent(self, agent: impl Into<String>) -> Self

Set the user agent

If not set, defaults to async_lastfm/VERSION

Source

pub fn timeout(self, duration: Duration) -> Self

Set the request timeout

If not set, defaults to 30 seconds

Source

pub fn max_concurrent_requests(self, max: usize) -> Self

Set maximum concurrent requests

If not set, defaults to 5

Source

pub fn retry_attempts(self, attempts: u32) -> Self

Set number of retry attempts

If not set, defaults to 3

Source

pub fn rate_limit(self, max_requests: u32, per_duration: Duration) -> Self

Set rate limiting

§Example
use lastfm_client::ConfigBuilder;
use std::time::Duration;

let builder = ConfigBuilder::new()
    .api_key("key")
    .rate_limit(5, Duration::from_secs(1)); // Max 5 requests per second
Source

pub fn build(self) -> Result<Config>

Build the configuration

§Errors

Returns an error if the API key is not set and cannot be loaded from environment

Source

pub fn build_with_defaults() -> Result<Config>

Build the configuration with defaults, trying to load API key from environment

This is equivalent to ConfigBuilder::new().build() but more explicit about the default behavior.

§Errors

Returns an error if the API key is not set and cannot be loaded from environment

Trait Implementations§

Source§

impl Debug for ConfigBuilder

Source§

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

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

impl Default for ConfigBuilder

Source§

fn default() -> ConfigBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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<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