Enum AsyncRuntime

Source
pub enum AsyncRuntime {
    TokioSingle,
    TokioShared,
    TokioOwned(Runtime),
}
Expand description

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(Runtime)

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§

Source§

impl AsyncRuntime

Source

pub fn make_default(self)

Make this runtime the default.

Trait Implementations§

Source§

impl Debug for AsyncRuntime

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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