pub struct MockRuntime { /* private fields */ }Expand description
A runtime on virtual time with an in-memory network (see the module documentation).
Implementations§
Source§impl MockRuntime
impl MockRuntime
Sourcepub fn new() -> Self
pub fn new() -> Self
A runtime whose clock reads the present moment, then moves only when told; loss drawn from seed 1.
Sourcepub fn set_auto_advance(&self, on: bool)
pub fn set_auto_advance(&self, on: bool)
Whether run moves the clock to the next timer when nothing can run
(on by default). Off, the clock moves only by MockClock::advance, and run panics
when it would have to wait.
Sourcepub fn run_until_idle(&self)
pub fn run_until_idle(&self)
Runs the tasks that can run now, without moving the clock.
Sourcepub fn run<F: Future>(&self, future: F) -> F::Output
pub fn run<F: Future>(&self, future: F) -> F::Output
Runs future to completion on this thread, with the runtime’s tasks, moving the clock
to the next timer whenever nothing can run.
§Panics
When nothing can run and no timer is pending (the future would wait forever), when
the clock may not advance by itself and something must wait, and when called from
inside another run of the same runtime.
Trait Implementations§
Source§impl Clone for MockRuntime
impl Clone for MockRuntime
Source§impl Debug for MockRuntime
impl Debug for MockRuntime
Source§impl Default for MockRuntime
impl Default for MockRuntime
Source§impl Runtime for MockRuntime
impl Runtime for MockRuntime
Source§fn spawn(&self, future: BoxFuture<'static, ()>) -> Box<dyn JoinHandle>
fn spawn(&self, future: BoxFuture<'static, ()>) -> Box<dyn JoinHandle>
Runs
future as a task of its own. Dropping the handle detaches the task (it runs on);
JoinHandle::abort cancels it.Source§fn now(&self) -> Instant
fn now(&self) -> Instant
The runtime’s clock. Every time the driver gives the engine comes from here, so a
virtual clock drives the engine’s timers too.
Source§fn sleep_until(&self, deadline: Instant) -> BoxFuture<'static, ()>
fn sleep_until(&self, deadline: Instant) -> BoxFuture<'static, ()>
A future that completes once
now has reached deadline (at once when it
has already).Source§fn bind_udp(&self, local: SocketAddr) -> Result<Arc<dyn AsyncUdpSocket>>
fn bind_udp(&self, local: SocketAddr) -> Result<Arc<dyn AsyncUdpSocket>>
A UDP socket bound to
local (port 0: any free port). Read moreSource§fn bind_udp_multicast(
&self,
config: &MulticastConfig,
) -> Result<Arc<dyn AsyncUdpSocket>>
fn bind_udp_multicast( &self, config: &MulticastConfig, ) -> Result<Arc<dyn AsyncUdpSocket>>
A UDP socket joined to a multicast group (mDNS: 224.0.0.251 or ff02::fb on 5353). Read more
Source§fn listen_tcp(
&self,
local: SocketAddr,
_reuse_address: bool,
) -> Result<Arc<dyn AsyncTcpListener>>
fn listen_tcp( &self, local: SocketAddr, _reuse_address: bool, ) -> Result<Arc<dyn AsyncTcpListener>>
A TCP listener on
local (backlog 128). reuse_address sets SO_REUSEADDR (and
SO_REUSEPORT where the platform has it). Read moreSource§fn connect_tcp(
&self,
local: SocketAddr,
remote: SocketAddr,
_reuse_address: bool,
) -> BoxFuture<'static, Result<Arc<dyn AsyncTcpStream>>>
fn connect_tcp( &self, local: SocketAddr, remote: SocketAddr, _reuse_address: bool, ) -> BoxFuture<'static, Result<Arc<dyn AsyncTcpStream>>>
A TCP connection from
local (bound first: an ICE-TCP active candidate’s address) to
remote, with TCP_NODELAY set. The driver bounds it with its connect timeout.Source§fn resolve_host(
&self,
host: &str,
port: u16,
) -> BoxFuture<'static, Result<Vec<SocketAddr>>>
fn resolve_host( &self, host: &str, port: u16, ) -> BoxFuture<'static, Result<Vec<SocketAddr>>>
The addresses of
host with port, both families together (the system resolver asks
for AAAA and A at once, RFC 8305 section 3).Source§fn block_on(&self, future: Pin<Box<dyn Future<Output = ()> + '_>>)
fn block_on(&self, future: Pin<Box<dyn Future<Output = ()> + '_>>)
Runs
future to completion on the calling thread. The future need not be Send.Source§fn virtual_clock(&self) -> bool
fn virtual_clock(&self) -> bool
Whether
now is a virtual clock (a mock’s) rather than the wall clock.
What is kept per process on the wall clock (the mDNS budget,
process_mdns_rate_limit) is not shared with a
driver on a virtual clock, whose times run elsewhere. false by default.Source§fn resolve_family(
&self,
host: &str,
port: u16,
ipv6: bool,
) -> Option<BoxFuture<'static, Vec<SocketAddr>>>
fn resolve_family( &self, host: &str, port: u16, ipv6: bool, ) -> Option<BoxFuture<'static, Vec<SocketAddr>>>
The addresses of one family of
host, when the runtime can ask for AAAA and A apart
(RFC 8305 section 3: the engine starts on the first answer). None, the default: it
cannot, and the driver uses resolve_host.Source§fn resolve_records(
&self,
name: &str,
kind: RecordKind,
) -> BoxFuture<'static, Vec<DnsRecord>>
fn resolve_records( &self, name: &str, kind: RecordKind, ) -> BoxFuture<'static, Vec<DnsRecord>>
The SRV or NAPTR records of
name (RFC 5928, RFC 8489 section 8). The default answers
none, and the engine then uses the host and the scheme’s default port.Auto Trait Implementations§
impl Forget for MockRuntime
impl Freeze for MockRuntime
impl Move for MockRuntime
impl RefUnwindSafe for MockRuntimewhere
Atomic<usize>: RefUnwindSafe,
Mutex<State>: RefUnwindSafe,
Mutex<VecDeque<Runnable>>: RefUnwindSafe,
Atomic<bool>: RefUnwindSafe,
impl Send for MockRuntime
impl Sync for MockRuntime
impl Unpin for MockRuntime
impl UnsafeUnpin for MockRuntime
impl UnwindSafe for MockRuntimewhere
Arc<Shared>: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.