pub struct PreferredRuntime { /* private fields */ }
native-tls
or rustls
) and (crate features async-std
or tokio
) only.Expand description
The runtime that we prefer to use, out of all the runtimes compiled into the tor-rtcompat crate.
If tokio
and async-std
are both available, we prefer tokio
for its
performance.
If native_tls
and rustls
are both available, we prefer native_tls
since
it has been used in Arti for longer.
Implementations§
source§impl PreferredRuntime
impl PreferredRuntime
sourcepub fn current() -> Result<Self>
pub fn current() -> Result<Self>
Obtain a PreferredRuntime
from the currently running asynchronous runtime.
Generally, this is what you want.
This tries to get a handle to a currently running asynchronous runtime, and
wraps it; the returned PreferredRuntime
isn’t the same thing as the
asynchronous runtime object itself (e.g. tokio::runtime::Runtime
).
§Panics
When tor-rtcompat
is compiled with the tokio
feature enabled
(regardless of whether the async-std
feature is also enabled),
panics if called outside of Tokio runtime context.
See tokio::runtime::Handle::current
.
§Usage notes
Once you have a runtime returned by this function, you should
just create more handles to it via Clone
.
§Limitations
If the tor-rtcompat
crate was compiled with tokio
support,
this function will never return a runtime based on async_std
.
sourcepub fn create() -> Result<Self>
pub fn create() -> Result<Self>
Create and return a new instance of the default Runtime
.
Generally you should call this function at most once, and then use
Clone::clone()
to create additional references to that runtime.
Tokio users may want to avoid this function and instead obtain a runtime using
PreferredRuntime::current
: this function always builds a runtime,
and if you already have a runtime, that isn’t what you want with Tokio.
If you need more fine-grained control over a runtime, you can create it using an appropriate builder type or function.
Trait Implementations§
source§impl BlockOn for PreferredRuntime
impl BlockOn for PreferredRuntime
source§impl Clone for PreferredRuntime
impl Clone for PreferredRuntime
source§fn clone(&self) -> PreferredRuntime
fn clone(&self) -> PreferredRuntime
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl CoarseTimeProvider for PreferredRuntime
impl CoarseTimeProvider for PreferredRuntime
source§fn now_coarse(&self) -> CoarseInstant
fn now_coarse(&self) -> CoarseInstant
CoarseTimeProvider
’s view of the current instant. Read moresource§impl Debug for PreferredRuntime
impl Debug for PreferredRuntime
source§impl NetStreamProvider<SocketAddr> for PreferredRuntime
impl NetStreamProvider<SocketAddr> for PreferredRuntime
source§type Stream = <TokioNativeTlsRuntime as NetStreamProvider<SocketAddr>>::Stream
type Stream = <TokioNativeTlsRuntime as NetStreamProvider<SocketAddr>>::Stream
Self::connect()
.source§type Listener = <TokioNativeTlsRuntime as NetStreamProvider<SocketAddr>>::Listener
type Listener = <TokioNativeTlsRuntime as NetStreamProvider<SocketAddr>>::Listener
Self::listen()
.source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
source§impl NetStreamProvider for PreferredRuntime
impl NetStreamProvider for PreferredRuntime
source§type Stream = <TokioNativeTlsRuntime as NetStreamProvider>::Stream
type Stream = <TokioNativeTlsRuntime as NetStreamProvider>::Stream
Self::connect()
.source§type Listener = <TokioNativeTlsRuntime as NetStreamProvider>::Listener
type Listener = <TokioNativeTlsRuntime as NetStreamProvider>::Listener
Self::listen()
.source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
source§impl SleepProvider for PreferredRuntime
impl SleepProvider for PreferredRuntime
source§type SleepFuture = <TokioNativeTlsRuntime as SleepProvider>::SleepFuture
type SleepFuture = <TokioNativeTlsRuntime as SleepProvider>::SleepFuture
SleepProvider::sleep()
source§fn sleep(&self, duration: Duration) -> Self::SleepFuture
fn sleep(&self, duration: Duration) -> Self::SleepFuture
duration
has
elapsed.source§fn wallclock(&self) -> SystemTime
fn wallclock(&self) -> SystemTime
source§fn block_advance<T: Into<String>>(&self, _reason: T)
fn block_advance<T: Into<String>>(&self, _reason: T)
source§fn release_advance<T: Into<String>>(&self, _reason: T)
fn release_advance<T: Into<String>>(&self, _reason: T)
block_advance
no
longer exists, and it’s fine to move time forward if nothing else is blocking advances. Read moresource§fn allow_one_advance(&self, _dur: Duration)
fn allow_one_advance(&self, _dur: Duration)
block_advance
API has been used. Read moresource§impl Spawn for PreferredRuntime
impl Spawn for PreferredRuntime
source§impl<S> TlsProvider<S> for PreferredRuntime
impl<S> TlsProvider<S> for PreferredRuntime
source§type Connector = <TokioNativeTlsRuntime as TlsProvider<S>>::Connector
type Connector = <TokioNativeTlsRuntime as TlsProvider<S>>::Connector
source§type TlsStream = <TokioNativeTlsRuntime as TlsProvider<S>>::TlsStream
type TlsStream = <TokioNativeTlsRuntime as TlsProvider<S>>::TlsStream
source§fn tls_connector(&self) -> Self::Connector
fn tls_connector(&self) -> Self::Connector
source§fn supports_keying_material_export(&self) -> bool
fn supports_keying_material_export(&self) -> bool
source§impl UdpProvider for PreferredRuntime
impl UdpProvider for PreferredRuntime
source§type UdpSocket = <TokioNativeTlsRuntime as UdpProvider>::UdpSocket
type UdpSocket = <TokioNativeTlsRuntime as UdpProvider>::UdpSocket
Self::bind()
Auto Trait Implementations§
impl Freeze for PreferredRuntime
impl !RefUnwindSafe for PreferredRuntime
impl Send for PreferredRuntime
impl Sync for PreferredRuntime
impl Unpin for PreferredRuntime
impl !UnwindSafe for PreferredRuntime
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> NetStreamProvider<SocketAddr> for T
impl<T> NetStreamProvider<SocketAddr> for T
source§type Stream = Stream
type Stream = Stream
Self::connect()
.source§type Listener = Listener
type Listener = Listener
Self::listen()
.source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Stream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = Result<Stream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait,
source§impl<R> RuntimeSubstExt for Rwhere
R: Runtime,
impl<R> RuntimeSubstExt for Rwhere
R: Runtime,
source§fn with_tcp_provider<T>(
&self,
new_tcp: T,
) -> CompoundRuntime<R, R, R, T, R, R, R>
fn with_tcp_provider<T>( &self, new_tcp: T, ) -> CompoundRuntime<R, R, R, T, R, R, R>
source§fn with_sleep_provider<T>(
&self,
new_sleep: T,
) -> CompoundRuntime<R, T, R, R, R, R, R>
fn with_sleep_provider<T>( &self, new_sleep: T, ) -> CompoundRuntime<R, T, R, R, R, R, R>
source§fn with_coarse_time_provider<T>(
&self,
new_coarse_time: T,
) -> CompoundRuntime<R, R, T, R, R, R, R>
fn with_coarse_time_provider<T>( &self, new_coarse_time: T, ) -> CompoundRuntime<R, R, T, R, R, R, R>
source§impl<T> SleepProviderExt for Twhere
T: SleepProvider,
impl<T> SleepProviderExt for Twhere
T: SleepProvider,
source§fn timeout<F: Future>(
&self,
duration: Duration,
future: F,
) -> Timeout<F, Self::SleepFuture> ⓘ
fn timeout<F: Future>( &self, duration: Duration, future: F, ) -> Timeout<F, Self::SleepFuture> ⓘ
source§fn sleep_until_wallclock(
&self,
when: SystemTime,
) -> SleepUntilWallclock<'_, Self>
fn sleep_until_wallclock( &self, when: SystemTime, ) -> SleepUntilWallclock<'_, Self>
when
or later, trying to
recover from clock jumps. Read more§impl<Sp> SpawnExt for Spwhere
Sp: Spawn + ?Sized,
impl<Sp> SpawnExt for Spwhere
Sp: Spawn + ?Sized,
§fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
alloc
only.()
to
completion. Read more