[][src]Struct spirit_reqwest::futures::AtomicClient

pub struct AtomicClient(_);

A storage for one Client that can be atomically exchanged under the hood.

This acts as a proxy for a Client. This is cheap to clone all cloned handles refer to the same client. It has most of the Client's methods directly on itself, the others can be accessed through the client method.

It also supports the replace method, by which it is possible to exchange the client inside.

While it can be used separately, it is best paired with a ReqwestClient configuration fragment inside Spirit to have an up to date client around.

Warning

As it is possible for the client to get replaced at any time by another thread, therefore successive calls to eg. get may happen on different clients. If this is a problem, a caller may get a specific client by the client method ‒ the client returned will not change for as long as it is held (if the one inside here is replaced, both are kept alive until the return value of client goes out of scope).

Panics

Trying to access the client if the AtomicClient was created with empty and wasn't set yet (either by Spirit or by explicit replace) will result into panic.

If you may use the client sooner, prefer either default or unconfigured.

Implementations

impl AtomicClient[src]

pub fn empty() -> Self[src]

Creates an empty AtomicClient.

This is effectively a NULL. It'll panic until a value is set, either by replace or by Spirit behind the scenes. It is appropriate if the caller is sure it will get configured before being accessed and creating an intermediate client first would be a waste.

pub fn unconfigured() -> Self[src]

Creates an AtomicClient with default Client inside.

pub fn replace<C: Into<Arc<Client>>>(&self, by: C)[src]

Replaces the content of this AtomicClient with a new Client.

If you want to create a new AtomicClient out of a client, use From. This is meant for replacing the content of already existing ones.

This replaces it for all connected handles (eg. created by cloning from the same original AtomicClient).

pub fn client(&self) -> Arc<Client>[src]

Returns a handle to the Client currently held inside.

This serves a dual purpose:

  • If some functionality is not directly provided by the AtomicClient proxy.
  • If the caller needs to ensure a series of requests is performed using the same client. While the content of the AtomicClient can change between calls to it, the content of the Arc can't. While it is possible the client inside AtomicClient exchanged, the Arc keeps its Client around (which may lead to multiple Clients in memory).

pub fn request<U: IntoUrl>(&self, method: Method, url: U) -> RequestBuilder[src]

Starts building an arbitrary request using the current client.

This is forwarded to Client::request.

pub fn get<U: IntoUrl>(&self, url: U) -> RequestBuilder[src]

Starts building a GET request.

This is forwarded to Client::get.

pub fn post<U: IntoUrl>(&self, url: U) -> RequestBuilder[src]

Starts building a POST request.

This is forwarded to Client::post.

pub fn put<U: IntoUrl>(&self, url: U) -> RequestBuilder[src]

Starts building a PUT request.

This is forwarded to Client::put.

pub fn patch<U: IntoUrl>(&self, url: U) -> RequestBuilder[src]

Starts building a PATCH request.

This is forwarded to Client::patch.

pub fn delete<U: IntoUrl>(&self, url: U) -> RequestBuilder[src]

Starts building a DELETE request.

This is forwarded to Client::delete.

pub fn head<U: IntoUrl>(&self, url: U) -> RequestBuilder[src]

Starts building a HEAD request.

This is forwarded to Client::head.

Trait Implementations

impl Clone for AtomicClient[src]

impl Debug for AtomicClient[src]

impl Default for AtomicClient[src]

impl<C: Into<Arc<Client>>> From<C> for AtomicClient[src]

impl<O, C> Installer<Client, O, C> for AtomicClient[src]

type UninstallHandle = ()

A handle representing lifetime of the resource. Read more

Auto Trait Implementations

impl !RefUnwindSafe for AtomicClient

impl Send for AtomicClient

impl Sync for AtomicClient

impl Unpin for AtomicClient

impl !UnwindSafe for AtomicClient

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoResult<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.