Enum hreq::AsyncRuntime[][src]

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

Switches between different async runtimes.

This is a global singleton.

hreq supports different ways of using tokio.

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

Variants

TokioSingle

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

TokioShared

Pick up on a tokio shared runtime.

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();
TokioOwned(TokioRuntime)

Use a tokio runtime owned by hreq.

Example using an owned tokio.

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

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

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

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