Skip to main content

MockRuntime

Struct MockRuntime 

Source
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

Source

pub fn new() -> Self

A runtime whose clock reads the present moment, then moves only when told; loss drawn from seed 1.

Source

pub fn with_seed(seed: u64) -> Self

As new, loss drawn from seed.

Source

pub fn clock(&self) -> MockClock

The virtual clock.

Source

pub fn net(&self) -> MockNet

The in-memory network.

Source

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.

Source

pub fn run_until_idle(&self)

Runs the tasks that can run now, without moving the clock.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MockRuntime

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for MockRuntime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Runtime for MockRuntime

Source§

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

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

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

A UDP socket bound to local (port 0: any free port). Read more
Source§

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

A TCP listener on local (backlog 128). reuse_address sets SO_REUSEADDR (and SO_REUSEPORT where the platform has it). Read more
Source§

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

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 = ()> + '_>>)

Runs future to completion on the calling thread. The future need not be Send.
Source§

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

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

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§

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

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 T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> LayoutRaw for T

Source§

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
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

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

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more