ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder<T: Client> { /* private fields */ }
Expand description

Builder for constructing booru API clients.

This builder allows you to configure various options before creating a client to query a booru site.

§Example

use booru_rs::danbooru::{DanbooruClient, DanbooruRating};
use booru_rs::client::Client;

let client = DanbooruClient::builder()
    .tag("cat_ears")?
    .rating(DanbooruRating::General)
    .limit(10)
    .build();

let posts = client.get().await?;

Implementations§

Source§

impl<T: Client> ClientBuilder<T>

Source

pub fn new() -> Self

Creates a new builder with default settings.

Uses the shared HTTP client for connection pooling.

Source

pub fn with_client(client: Client) -> Self

Creates a new builder with a custom HTTP client.

Use this when you need custom HTTP configuration (e.g., proxy, custom TLS).

Source

pub fn with_custom_url(self, url: &str) -> Self

Sets a custom base URL for the API.

This is primarily useful for testing with mock servers.

Source

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

Sets the API key and username for authenticated requests.

Some booru sites require or benefit from authentication.

Source

pub fn tag(self, tag: impl Into<String>) -> Result<Self>

Adds a tag to the search query.

§Errors

Returns BooruError::TagLimitExceeded if adding this tag would exceed the client’s maximum tag limit.

§Example
use booru_rs::danbooru::DanbooruClient;
use booru_rs::client::Client;

let client = DanbooruClient::builder()
    .tag("cat_ears")?
    .tag("blue_eyes")?
    .build();
Source

pub fn rating(self, rating: T::Rating) -> Self

Adds a rating filter to the search query.

The rating type is specific to each booru site, ensuring compile-time type safety.

§Example
use booru_rs::danbooru::{DanbooruClient, DanbooruRating};
use booru_rs::client::Client;

let client = DanbooruClient::builder()
    .rating(DanbooruRating::General)
    .build();
Source

pub fn limit(self, limit: u32) -> Self

Sets the maximum number of posts to retrieve.

Default is 100, which is also typically the maximum allowed by most APIs.

Source

pub fn random(self) -> Self

Enables random ordering of results.

Source

pub fn sort(self, order: Sort) -> Self

Adds a sort order to the query.

Source

pub fn blacklist_tag(self, tag: impl Into<String>) -> Self

Excludes posts with the specified tag.

Multiple blacklist tags can be added by calling this method multiple times.

Source

pub fn default_url(self, url: impl Into<String>) -> Self

Overrides the default API URL.

Useful for testing or accessing mirror sites.

Source

pub fn page(self, page: u32) -> Self

Sets the page number for pagination.

Page numbering starts at 0.

Source

pub fn tags<I, S>(self, tags: I) -> Result<Self>
where I: IntoIterator<Item = S>, S: Into<String>,

Adds multiple tags to the search query at once.

§Errors

Returns BooruError::TagLimitExceeded if adding these tags would exceed the client’s maximum tag limit.

§Example
use booru_rs::prelude::*;

let client = GelbooruClient::builder()
    .tags(["cat_ears", "blue_eyes", "1girl"])?
    .build();
Source

pub fn blacklist_tags<I, S>(self, tags: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Excludes multiple tags from the search query at once.

§Example
use booru_rs::prelude::*;

let client = GelbooruClient::builder()
    .tag("cat_ears")?
    .blacklist_tags(["ugly", "low_quality"])
    .build();
Source

pub fn tag_count(&self) -> usize

Returns the current number of tags in the query.

Source

pub fn has_tags(&self) -> bool

Returns true if the builder has any tags configured.

Source

pub fn build(self) -> T

Builds the client with the configured options.

Source§

impl<T: Client> ClientBuilder<T>

Source

pub fn into_page_stream(self) -> PageStream<T>

Creates an async stream that yields pages of posts.

Each call to next() fetches and returns a full page of posts.

§Example
use booru_rs::prelude::*;

let mut stream = SafebooruClient::builder()
    .tag("landscape")?
    .limit(100)
    .into_page_stream();

while let Some(page_result) = stream.next().await {
    let posts = page_result?;
    if posts.is_empty() { break; }
    println!("Page with {} posts", posts.len());
}
Source

pub fn into_post_stream(self) -> PostStream<T>

Creates an async stream that yields individual posts.

Automatically handles pagination, fetching new pages as needed.

§Example
use booru_rs::prelude::*;

let mut stream = SafebooruClient::builder()
    .tag("landscape")?
    .limit(100)
    .into_post_stream()
    .max_posts(250);

while let Some(post_result) = stream.next().await {
    let post = post_result?;
    println!("Post #{}", post.id);
}

Trait Implementations§

Source§

impl<T: Client> Clone for ClientBuilder<T>

Source§

fn clone(&self) -> Self

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<T: Debug + Client> Debug for ClientBuilder<T>

Source§

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

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

impl<T: Client> Default for ClientBuilder<T>

Source§

fn default() -> Self

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

impl From<ClientBuilder<DanbooruClient>> for DanbooruClient

Source§

fn from(value: ClientBuilder<Self>) -> Self

Converts to this type from the input type.
Source§

impl From<ClientBuilder<GelbooruClient>> for GelbooruClient

Source§

fn from(value: ClientBuilder<Self>) -> Self

Converts to this type from the input type.
Source§

impl From<ClientBuilder<Rule34Client>> for Rule34Client

Source§

fn from(value: ClientBuilder<Self>) -> Self

Converts to this type from the input type.
Source§

impl From<ClientBuilder<SafebooruClient>> for SafebooruClient

Source§

fn from(value: ClientBuilder<Self>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for ClientBuilder<T>

§

impl<T> !RefUnwindSafe for ClientBuilder<T>

§

impl<T> Send for ClientBuilder<T>

§

impl<T> Sync for ClientBuilder<T>

§

impl<T> Unpin for ClientBuilder<T>
where T: Unpin,

§

impl<T> !UnwindSafe for ClientBuilder<T>

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