pub trait Runtime:
Send
+ Sync
+ Debug
+ 'static {
Show 15 methods
// Required methods
fn spawn(&self, future: BoxFuture<'static, ()>) -> Box<dyn JoinHandle>;
fn now(&self) -> Instant;
fn sleep_until(&self, deadline: Instant) -> BoxFuture<'static, ()>;
fn bind_udp(&self, local: SocketAddr) -> Result<Arc<dyn AsyncUdpSocket>>;
fn bind_udp_multicast(
&self,
config: &MulticastConfig,
) -> Result<Arc<dyn AsyncUdpSocket>>;
fn listen_tcp(
&self,
local: SocketAddr,
reuse_address: bool,
) -> Result<Arc<dyn AsyncTcpListener>>;
fn connect_tcp(
&self,
local: SocketAddr,
remote: SocketAddr,
reuse_address: bool,
) -> BoxFuture<'static, Result<Arc<dyn AsyncTcpStream>>>;
fn resolve_host(
&self,
host: &str,
port: u16,
) -> BoxFuture<'static, Result<Vec<SocketAddr>>>;
fn block_on(&self, future: Pin<Box<dyn Future<Output = ()> + '_>>);
// Provided methods
fn resolve_family(
&self,
host: &str,
port: u16,
ipv6: bool,
) -> Option<BoxFuture<'static, Vec<SocketAddr>>> { ... }
fn resolve_records(
&self,
name: &str,
kind: RecordKind,
) -> BoxFuture<'static, Vec<DnsRecord>> { ... }
fn virtual_clock(&self) -> bool { ... }
fn interfaces(&self) -> Result<Vec<LocalInterface>> { ... }
fn preferred_source(&self, ipv6: bool) -> Option<IpAddr> { ... }
fn route_source(&self, destination: IpAddr) -> Option<IpAddr> { ... }
}Expand description
What a driver needs from an async runtime: the primitives that touch a reactor or a clock.
Object safe (&self receivers, no generic methods): drivers hold an Arc<dyn Runtime>.
See the module documentation for what is and is not here.
Required Methods§
Sourcefn 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.
Sourcefn 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.
Sourcefn 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).
Sourcefn 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).
§Errors
The bind failed: AddrInUse for a port in use, PermissionDenied for one the host
refuses (both are skipped inside a port range).
Sourcefn 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).
§Errors
The bind or the join failed (a host without IPv6, say).
Sourcefn 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>>
Sourcefn 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.
Sourcefn 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).
Provided Methods§
Sourcefn 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.
Sourcefn 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.
Sourcefn 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.
Sourcefn interfaces(&self) -> Result<Vec<LocalInterface>>
fn interfaces(&self) -> Result<Vec<LocalInterface>>
Every address of every interface of the host that is up, unfiltered: what address
selection (crate::sockets::AddressSelection) chooses from. The default reads the
operating system’s list (host_interfaces); a runtime with a network of its own (a
mock’s) answers with that network’s.
§Errors
The list could not be read.
Sourcefn preferred_source(&self, ipv6: bool) -> Option<IpAddr>
fn preferred_source(&self, ipv6: bool) -> Option<IpAddr>
The source address the system would use towards a global destination of the family
(IPv6 when ipv6): the default route’s address, None without a route. With IPv6
privacy extensions (RFC 8981) it is the temporary address (RFC 6724 rule 7). The
default asks the system with an unconnected UDP socket connected to a documentation
address (RFC 5737, RFC 3849): connecting a UDP socket sends nothing.
Sourcefn route_source(&self, destination: IpAddr) -> Option<IpAddr>
fn route_source(&self, destination: IpAddr) -> Option<IpAddr>
The source address the system’s routing table picks towards destination (None
without a route): RFC 8828 section 5.2 Mode 2 “MUST follow the kernel routing table
rules”, and with an enterprise TURN server “the preferred route MUST be through” it, so
the interface of the route to that server is the one gathered on. The default asks the
system with a UDP socket connected to destination (connecting sends nothing).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".