Struct Client

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

Represents a client for interacting with an API.

The Client struct contains the necessary configuration for making requests to an API, including the API token and the timeout duration.

Implementations§

Source§

impl Client

Source

pub fn with_timeout(duration: Duration) -> Self

Creates a new client instance with the specified timeout duration.

This method initializes a new Client instance with the provided timeout duration.

§Arguments
  • timeout - The timeout duration for requests, in seconds.
Source

pub fn with_token(token: &str) -> Self

Creates a new client instance with the specified API token.

This method initializes a new Client instance with the provided API token and a default timeout duration of 20 seconds.

§Arguments
  • token - A string slice that holds the API token.
Source

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

Sets the timeout duration for the client.

This method allows you to set the timeout duration for the client in seconds. The timeout duration determines how long the client will wait for a response before timing out.

§Arguments
  • seconds - The timeout duration in seconds.
Source

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

Sets the API token for the client.

This method allows you to set the API token for the client, which will be used for authenticating API requests.

§Arguments
  • token - A string slice that holds the API token.
Source

pub async fn get_anime(&self, id: i64) -> Result<Anime>

Get an anime by its ID or MAL ID.

§Arguments
  • id - The ID of the anime.
  • mal_id - The MAL ID of the anime.
§Errors

Returns an error if the request fails.

§Example
let anime = client.get_anime(1).await?;
Source

pub async fn get_manga(&self, id: i64) -> Result<Manga>

Get a manga by its ID or MAL ID.

§Arguments
  • id - The ID of the manga.
  • mal_id - The MAL ID of the manga.
§Errors

Returns an error if the request fails.

§Example
let manga = client.get_manga(1).await?;
Source

pub async fn get_character(&self, id: i64) -> Result<Character>

Get a character by its ID.

§Arguments
  • id - The ID of the character.
§Errors

Returns an error if the request fails.

§Example
let character = client.get_character(1).await?;
Source

pub async fn get_char(&self, id: i64) -> Result<Character>

Get a character by its ID.

§Arguments
  • id - The ID of the character.
§Errors

Returns an error if the request fails.

§Example
let character = client.get_char(1).await?;
Source

pub async fn get_user(&self, id: i32) -> Result<User>

Get a user by its ID.

§Arguments
  • id - The ID of the user.
§Errors

Returns an error if the request fails.

§Example
let user = client.get_user(1).await?;
Source

pub async fn get_user_by_name<N: ToString>(&self, name: N) -> Result<User>

Get a user by its name.

§Arguments
  • name - The name of the user.
§Errors

Returns an error if the request fails.

§Example
let user = client.get_user_by_name("andrielfr").await?;
Source

pub async fn get_person(&self, id: i64) -> Result<Person>

Get a person by its ID.

§Arguments
  • id - The ID of the person.
§Errors

Returns an error if the request fails.

§Example
let person = client.get_person(1).await?;
Source

pub async fn search_anime( &self, title: &str, page: u16, limit: u16, ) -> Option<Vec<Anime>>

Search for animes.

§Arguments
  • title - The title of the anime to search.
  • page - The page number to get.
  • limit - The number of animes to get per page.
§Errors

Returns an error if the request fails.

§Example
let animes = client.search_anime("Naruto", 1, 10).await.unwrap();
Source

pub async fn search_manga( &self, title: &str, page: u16, limit: u16, ) -> Option<Vec<Manga>>

Search for mangas.

§Arguments
  • title - The title of the manga to search.
  • page - The page number to get.
  • limit - The number of mangas to get per page.
§Errors

Returns an error if the request fails.

§Example
let mangas = client.search_manga("Naruto", 1, 10).await.unwrap();
Source

pub async fn search_user( &self, name: &str, page: u16, limit: u16, ) -> Option<Vec<User>>

Search for users.

§Arguments
  • name - The name of the user to search.
  • page - The page number to get.
  • limit - The number of users to get per page.
§Errors

Returns an error if the request fails.

§Example
let users = client.search_user("andrielfr", 1, 10).await.unwrap();

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

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 Debug for Client

Source§

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

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

impl Default for Client

Source§

fn default() -> Self

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

impl PartialEq for Client

Source§

fn eq(&self, other: &Client) -> 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 StructuralPartialEq for Client

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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

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