[][src]Enum hreq::AsyncRuntime

pub enum AsyncRuntime {
    AsyncStd,
    TokioSingle,
    TokioShared,
    TokioOwned(TokioRuntime),
}

Switches between different async runtimes.

This is a global singleton.

hreq supports async-std and tokio. Tokio support is enabled by default and comes in some different flavors.

  • AsyncStd. Requires the feature async-std. Supports .block().
  • TokioSingle. The default option. A minimal tokio rt-core which executes calls in one single thread. It does nothing until the current thread blocks on a future using .block().
  • TokioShared. Picks up on a globally shared runtime by using a Handle. This runtime cannot use the .block() extension trait since that requires having a direct connection to the tokio Runtime.
  • TokioOwned. Uses a preconfigured tokio Runtime that is "handed over" to hreq.

Example using AsyncStd:

use hreq::AsyncRuntime;
#[cfg(feature = "async-std")]
AsyncRuntime::AsyncStd.make_default();

Example using a shared tokio.

use hreq::AsyncRuntime;

// assuming the current thread has some tokio runtime, such
// as using the `#[tokio::main]` macro on `fn main() { .. }`

AsyncRuntime::TokioShared.make_default();

Example using an owned tokio.

use hreq::AsyncRuntime;
// normally: use tokio::runtime::Builder;
use tokio_lib::runtime::Builder;

let runtime = Builder::new()
  .enable_io()
  .enable_time()
  .build()
  .expect("Failed to build tokio runtime");

AsyncRuntime::TokioOwned(runtime).make_default();

Variants

AsyncStd

Use async-std crate.

TokioSingle

Use a tokio rt-core single threaded runtime. This is the default.

TokioShared

Pick up on a tokio shared runtime.

TokioOwned(TokioRuntime)

Use a tokio runtime owned by hreq.

Implementations

impl AsyncRuntime[src]

pub fn make_default(self)[src]

Make this runtime the default.

Trait Implementations

impl Debug for AsyncRuntime[src]

Auto Trait Implementations

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, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Sealed<T> for T where
    T: ?Sized

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.

impl<T> WithSubscriber for T[src]