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 Blocking for PreferredRuntime
impl Blocking for PreferredRuntime
Source§type ThreadHandle<T: Send + 'static> = <TokioNativeTlsRuntime as Blocking>::ThreadHandle<T>
type ThreadHandle<T: Send + 'static> = <TokioNativeTlsRuntime as Blocking>::ThreadHandle<T>
spawn_blocking
Source§fn spawn_blocking<F, T>(
&self,
f: F,
) -> <PreferredRuntime as Blocking>::ThreadHandle<T>
fn spawn_blocking<F, T>( &self, f: F, ) -> <PreferredRuntime as Blocking>::ThreadHandle<T>
Source§fn reenter_block_on<F>(&self, future: F) -> F::Output
fn reenter_block_on<F>(&self, future: F) -> F::Output
Blocking::spawn_blocking
Read moreSource§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 ToplevelBlockOn for PreferredRuntime
impl ToplevelBlockOn for PreferredRuntime
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,
§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