Client

Struct Client 

Source
pub struct Client<Req, Resp>
where Req: Send + Sync + 'static, Resp: Send + Sync + 'static,
{ /* private fields */ }
Expand description

A client for sending requests and receiving responses.

The client is thread-safe and can be cloned to share across multiple tasks. It supports both single and batch requests, with configurable timeouts.

§Type Parameters

  • Req: The type of the request, must be Send + Sync + 'static.
  • Resp: The type of the response, must be Send + Sync + 'static.

Implementations§

Source§

impl<Req, Resp> Client<Req, Resp>
where Req: Send + Sync + 'static, Resp: Send + Sync + 'static,

Source

pub async fn request_timeout( &self, req: Req, timeout: Duration, ) -> Result<Resp, Error>

Sends a single request with a custom timeout.

§Parameters
  • req: The request to send.
  • timeout: The maximum duration to wait for a response.
§Returns
  • Ok(Resp): The response from the server.
  • Err(Error): An error if the request fails or times out.
Source

pub async fn request(&self, req: Req) -> Result<Resp, Error>

Sends a single request with the default timeout.

§Parameters
  • req: The request to send.
§Returns
  • Ok(Resp): The response from the server.
  • Err(Error): An error if the request fails or times out.
Source

pub async fn request_batch_timeout<ReqSeq>( &self, reqs: ReqSeq, timeout: Duration, concurrency: usize, ) -> Result<Vec<Resp>, Error>
where ReqSeq: IntoIterator<Item = Req> + Send + 'static,

Sends a batch of requests with a custom timeout and concurrency limit.

§Parameters
  • reqs: An iterator of requests to send.
  • timeout: The maximum duration to wait for all responses.
  • concurrency: The maximum number of concurrent requests.
§Returns
  • Ok(Vec<Resp>): A vector of responses from the server.
  • Err(Error): An error if any request fails or times out.
Source

pub async fn request_batch<ReqSeq>( &self, reqs: ReqSeq, concurrency: usize, ) -> Result<Vec<Resp>, Error>
where ReqSeq: IntoIterator<Item = Req> + Send + 'static,

Sends a batch of requests with the default timeout and a concurrency limit.

§Parameters
  • reqs: An iterator of requests to send.
  • concurrency: The maximum number of concurrent requests.
§Returns
  • Ok(Vec<Resp>): A vector of responses from the server.
  • Err(Error): An error if any request fails or times out.

Trait Implementations§

Source§

impl<Req, Resp> Clone for Client<Req, Resp>
where Req: Send + Sync + 'static + Clone, Resp: Send + Sync + 'static + Clone,

Source§

fn clone(&self) -> Client<Req, Resp>

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

Auto Trait Implementations§

§

impl<Req, Resp> Freeze for Client<Req, Resp>

§

impl<Req, Resp> !RefUnwindSafe for Client<Req, Resp>

§

impl<Req, Resp> Send for Client<Req, Resp>

§

impl<Req, Resp> Sync for Client<Req, Resp>

§

impl<Req, Resp> Unpin for Client<Req, Resp>

§

impl<Req, Resp> !UnwindSafe for Client<Req, Resp>

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