pub unsafe trait Backend: Sized + 'static {
type Wake: Wake;
type Detached: Send + 'static;
const FILESYSTEM: Filesystem = _;
Show 36 methods
// Required methods
fn new(config: &Config, pool: BufferPool) -> Result<Self, Error>;
fn now(&self) -> Instant;
fn waker(&self) -> Arc<Self::Wake> ⓘ;
fn open(&mut self, handle: Handle, spec: Open) -> Result<(), Error>;
fn local_addr(&self, handle: Handle) -> Result<SocketAddr, Error>;
fn submit(&mut self, request: Request) -> Result<(), Error>;
fn cancel(&mut self, op: OpId) -> Result<(), Error>;
fn has_work(&self) -> bool;
fn poll(
&mut self,
timeout: Option<Duration>,
budget: Budget,
events: &mut Vec<Event<Self::Detached>>,
) -> Result<PollInfo, Error>;
fn release(&mut self, handle: Handle);
fn detach(&mut self, handle: Handle) -> Result<Self::Detached, Error>;
fn attach(
&mut self,
handle: Handle,
transport: Self::Detached,
) -> Result<(), Error>;
fn integration(&mut self) -> Result<Integration, Error>;
// Provided methods
fn open_bound_tcp(
&mut self,
_handle: Handle,
_transport: Self::Detached,
_peer: SocketAddr,
_opts: TcpOpts,
) -> Result<(), Error> { ... }
fn fs(
&mut self,
_op: OpId,
_handle: Option<Handle>,
_request: FsRequest,
) -> Result<(), Error> { ... }
fn fs_watch(
&mut self,
_handle: Handle,
_path: &FsPath,
_options: WatchOptions,
) -> Result<(), Error> { ... }
fn set_notifier(&mut self, _notifier: Notifier) { ... }
fn spawn(
&mut self,
_handle: Handle,
_pipes: [Option<Handle>; 3],
_extra: &[Option<Handle>],
_spec: &ProcessSpec,
) -> Result<u32, Error> { ... }
fn prepare_close(&mut self, _handle: Handle) -> Result<(), Error> { ... }
fn kill(
&mut self,
_handle: Handle,
_signal: Signal,
_group: bool,
) -> Result<(), Error> { ... }
fn signal(&mut self, _handle: Handle, _signal: Signal) -> Result<(), Error> { ... }
fn tty_set_mode(
&mut self,
_handle: Handle,
_mode: TtyMode,
) -> Result<(), Error> { ... }
fn set_option(
&mut self,
_handle: Handle,
_option: SocketOption,
) -> Result<(), Error> { ... }
fn shutdown_receive(&mut self, _handle: Handle) -> Result<(), Error> { ... }
fn get_option(
&self,
_handle: Handle,
_kind: SocketOptionKind,
) -> Result<SocketOption, Error> { ... }
fn set_keepalive_parameters(
&mut self,
_handle: Handle,
_value: KeepAlive,
) -> Result<(), Error> { ... }
fn keepalive_parameters(&self, _handle: Handle) -> Result<KeepAlive, Error> { ... }
fn set_listen_backlog(
&mut self,
_handle: Handle,
_backlog: u32,
) -> Result<(), Error> { ... }
fn shutdown_read(&mut self, _handle: Handle) -> Result<(), Error> { ... }
fn raw_transport(&self, _handle: Handle) -> Result<RawTransport, Error> { ... }
fn tty_window_size(&self, _handle: Handle) -> Result<WindowSize, Error> { ... }
fn validate_timeout(&self, _timeout: Timeout) -> Result<(), Error> { ... }
fn deadline_changed(&mut self, _deadline: Option<Instant>) { ... }
fn resolve(&mut self, _op: OpId, _request: &DnsRequest) -> Result<(), Error> { ... }
fn attach_tcp_connect(
&mut self,
_handle: Handle,
_transport: Self::Detached,
_destination: SocketAddr,
) -> Result<(), Error> { ... }
fn attach_tcp_connect_unbound(
&mut self,
_handle: Handle,
_transport: Self::Detached,
_destination: SocketAddr,
) -> Result<(), Error> { ... }
}Expand description
§Safety
Implementers must uphold the buffer-lifetime and native-quiescence guarantees above: no native I/O may access a buffer after its terminal Event or Drop. Core lifetime and handle-release safety relies on those guarantees.
Provided Associated Constants§
Sourceconst FILESYSTEM: Filesystem = _
const FILESYSTEM: Filesystem = _
Where typed filesystem requests run for this backend.
Required Associated Types§
Required Methods§
Sourcefn new(config: &Config, pool: BufferPool) -> Result<Self, Error>
fn new(config: &Config, pool: BufferPool) -> Result<Self, Error>
Construct backend storage and native wait resources with the supplied shared read pool.
Sourcefn now(&self) -> Instant
fn now(&self) -> Instant
Monotonic, nondecreasing time in a consistent domain across calls. Native adapters return std::time::Instant::now(). Web adapters construct crate::Instant::from_duration from their monotonic host clock. This method must not schedule work, block, or invoke a user callback.
Sourcefn waker(&self) -> Arc<Self::Wake> ⓘ
fn waker(&self) -> Arc<Self::Wake> ⓘ
Clone the lifetime-safe native wake endpoint for this backend.
Sourcefn open(&mut self, handle: Handle, spec: Open) -> Result<(), Error>
fn open(&mut self, handle: Handle, spec: Open) -> Result<(), Error>
Bind a new resource to the supplied handle, retaining nothing on error.
Sourcefn local_addr(&self, handle: Handle) -> Result<SocketAddr, Error>
fn local_addr(&self, handle: Handle) -> Result<SocketAddr, Error>
Return the local IP endpoint of a bound socket.
Sourcefn submit(&mut self, request: Request) -> Result<(), Error>
fn submit(&mut self, request: Request) -> Result<(), Error>
Accept one operation or reject it before retaining native buffer access.
Sourcefn cancel(&mut self, op: OpId) -> Result<(), Error>
fn cancel(&mut self, op: OpId) -> Result<(), Error>
Request cancellation; terminal acknowledgement must precede memory reuse.
Sourcefn has_work(&self) -> bool
fn has_work(&self) -> bool
Whether completions or immediately runnable cached operations are available.
Sourcefn poll(
&mut self,
timeout: Option<Duration>,
budget: Budget,
events: &mut Vec<Event<Self::Detached>>,
) -> Result<PollInfo, Error>
fn poll( &mut self, timeout: Option<Duration>, budget: Budget, events: &mut Vec<Event<Self::Detached>>, ) -> Result<PollInfo, Error>
Append bounded completions, performing at most one OS wait with the
supplied exact timeout, and delivering no more multishot connections
than budget allows.
Sourcefn release(&mut self, handle: Handle)
fn release(&mut self, handle: Handle)
Release a quiescent resource after Closed was appended to host output.
Sourcefn detach(&mut self, handle: Handle) -> Result<Self::Detached, Error>
fn detach(&mut self, handle: Handle) -> Result<Self::Detached, Error>
Unregister a quiescent resource and return its owning transferable representation.
Sourcefn attach(
&mut self,
handle: Handle,
transport: Self::Detached,
) -> Result<(), Error>
fn attach( &mut self, handle: Handle, transport: Self::Detached, ) -> Result<(), Error>
Register an owning transport on this loop; failure drops the rejected transport.
Sourcefn integration(&mut self) -> Result<Integration, Error>
fn integration(&mut self) -> Result<Integration, Error>
Opt into external host waiting and return the borrowed integration primitive.
Provided Methods§
Sourcefn open_bound_tcp(
&mut self,
_handle: Handle,
_transport: Self::Detached,
_peer: SocketAddr,
_opts: TcpOpts,
) -> Result<(), Error>
fn open_bound_tcp( &mut self, _handle: Handle, _transport: Self::Detached, _peer: SocketAddr, _opts: TcpOpts, ) -> Result<(), Error>
Adopt an exclusively owned, bound but unconnected TCP transport and configure its peer before a Connect request. Preserve the local binding and existing socket options; apply nodelay when requested. On error, retain no resource or native registration. Backends without native transport adoption return Unsupported.
Sourcefn fs(
&mut self,
_op: OpId,
_handle: Option<Handle>,
_request: FsRequest,
) -> Result<(), Error>
fn fs( &mut self, _op: OpId, _handle: Option<Handle>, _request: FsRequest, ) -> Result<(), Error>
Accept a typed filesystem request (only with Filesystem::Backend). handle
is the request’s file handle, or the new handle for an open.
Sourcefn fs_watch(
&mut self,
_handle: Handle,
_path: &FsPath,
_options: WatchOptions,
) -> Result<(), Error>
fn fs_watch( &mut self, _handle: Handle, _path: &FsPath, _options: WatchOptions, ) -> Result<(), Error>
Bind a native filesystem watch to a new handle, retaining nothing on error.
Sourcefn set_notifier(&mut self, _notifier: Notifier)
fn set_notifier(&mut self, _notifier: Notifier)
Give process-wide services this loop’s parking-aware notification endpoint.
Sourcefn spawn(
&mut self,
_handle: Handle,
_pipes: [Option<Handle>; 3],
_extra: &[Option<Handle>],
_spec: &ProcessSpec,
) -> Result<u32, Error>
fn spawn( &mut self, _handle: Handle, _pipes: [Option<Handle>; 3], _extra: &[Option<Handle>], _spec: &ProcessSpec, ) -> Result<u32, Error>
Spawn and bind the child and requested parent pipe handles atomically. Failure must release all supplied handles and reap any created child.
extra is parallel to spec.extra: a handle is supplied for every entry
whose source has a parent end, and None for the rest. The core has
already checked descriptor numbers and duplicates.
Sourcefn prepare_close(&mut self, _handle: Handle) -> Result<(), Error>
fn prepare_close(&mut self, _handle: Handle) -> Result<(), Error>
Begin nonblocking resource teardown before the core cancels its operations. Process backends terminate the owned child/tree here and defer its terminal acknowledgement until exit/reaping, so release never blocks a normal turn. Other resources need no action. An error leaves the core handle open.
Sourcefn kill(
&mut self,
_handle: Handle,
_signal: Signal,
_group: bool,
) -> Result<(), Error>
fn kill( &mut self, _handle: Handle, _signal: Signal, _group: bool, ) -> Result<(), Error>
Signal an owned child, or its explicitly isolated process group.
Sourcefn signal(&mut self, _handle: Handle, _signal: Signal) -> Result<(), Error>
fn signal(&mut self, _handle: Handle, _signal: Signal) -> Result<(), Error>
Bind a process-wide signal subscription to a new core handle.
Sourcefn tty_set_mode(&mut self, _handle: Handle, _mode: TtyMode) -> Result<(), Error>
fn tty_set_mode(&mut self, _handle: Handle, _mode: TtyMode) -> Result<(), Error>
Set a terminal mode, retaining the original settings until release/drop.
Sourcefn set_option(
&mut self,
_handle: Handle,
_option: SocketOption,
) -> Result<(), Error>
fn set_option( &mut self, _handle: Handle, _option: SocketOption, ) -> Result<(), Error>
Apply one socket option to a live resource, synchronously, through the OS. No Request is accepted and no Event is produced. A platform without an equivalent returns Unsupported; silently ignoring an option is forbidden, because a host cannot tell an ignored option from an applied one.
Sourcefn shutdown_receive(&mut self, _handle: Handle) -> Result<(), Error>
fn shutdown_receive(&mut self, _handle: Handle) -> Result<(), Error>
Synchronously request native receive-side shutdown without closing the send direction. Existing accepted requests retain their normal buffer ownership and terminal acknowledgement requirements. Unsupported transports must fail without changing either direction.
Sourcefn get_option(
&self,
_handle: Handle,
_kind: SocketOptionKind,
) -> Result<SocketOption, Error>
fn get_option( &self, _handle: Handle, _kind: SocketOptionKind, ) -> Result<SocketOption, Error>
Read one socket option from the OS. Backends never answer from a cache of what was set: the kernel may round, clamp or double a request, and the caller is entitled to the value the kernel actually holds.
Sourcefn set_keepalive_parameters(
&mut self,
_handle: Handle,
_value: KeepAlive,
) -> Result<(), Error>
fn set_keepalive_parameters( &mut self, _handle: Handle, _value: KeepAlive, ) -> Result<(), Error>
Set TCP keep-alive timing without changing SO_KEEPALIVE.
Sourcefn keepalive_parameters(&self, _handle: Handle) -> Result<KeepAlive, Error>
fn keepalive_parameters(&self, _handle: Handle) -> Result<KeepAlive, Error>
Query TCP keep-alive timing even while SO_KEEPALIVE is disabled.
Sourcefn set_listen_backlog(
&mut self,
_handle: Handle,
_backlog: u32,
) -> Result<(), Error>
fn set_listen_backlog( &mut self, _handle: Handle, _backlog: u32, ) -> Result<(), Error>
Change an already-listening TCP socket’s backlog.
Sourcefn shutdown_read(&mut self, _handle: Handle) -> Result<(), Error>
fn shutdown_read(&mut self, _handle: Handle) -> Result<(), Error>
Shut down receive after read operations have been acknowledged. Pending writes remain valid. A pending receive returns WouldBlock.
Sourcefn raw_transport(&self, _handle: Handle) -> Result<RawTransport, Error>
fn raw_transport(&self, _handle: Handle) -> Result<RawTransport, Error>
Report the native identity of a live transport, for the host only.
The core never acts on the value and never stores it: it reads it out of
the backend’s own table and returns it, so a host can implement Node’s
socket._handle.fd. Backends return Unsupported for a resource with no
descriptor identity of its own (timers, processes, signals, watches, and
every WASI/web resource). See Driver::raw_transport for the host rules.
Sourcefn tty_window_size(&self, _handle: Handle) -> Result<WindowSize, Error>
fn tty_window_size(&self, _handle: Handle) -> Result<WindowSize, Error>
Query current terminal dimensions.
Sourcefn validate_timeout(&self, _timeout: Timeout) -> Result<(), Error>
fn validate_timeout(&self, _timeout: Timeout) -> Result<(), Error>
Validate the original request even when queued completions eliminate the effective wait. Browser main-thread adapters reject every timeout but Now; a worker adapter may support blocking. Native adapters use this default.
Sourcefn deadline_changed(&mut self, _deadline: Option<Instant>)
fn deadline_changed(&mut self, _deadline: Option<Instant>)
The core owns timer semantics. Callback-driven adapters arm one host timer for this earliest deadline, whose callback schedules a turn. None disarms it. Native pollers need no action: poll receives the effective timeout. This is a scheduling import, never a user callback. If host scheduling fails, preserve the failure and return it from poll; never fake expiry.
Sourcefn resolve(&mut self, _op: OpId, _request: &DnsRequest) -> Result<(), Error>
fn resolve(&mut self, _op: OpId, _request: &DnsRequest) -> Result<(), Error>
Start a handle-free host name lookup. The default uses no resources and lets the core fall back to its native blocking pool. Accepted requests obey the same terminal/cancellation and no-spin rules as socket I/O.
Sourcefn attach_tcp_connect(
&mut self,
_handle: Handle,
_transport: Self::Detached,
_destination: SocketAddr,
) -> Result<(), Error>
fn attach_tcp_connect( &mut self, _handle: Handle, _transport: Self::Detached, _destination: SocketAddr, ) -> Result<(), Error>
Adopt an explicitly bound TCP socket and install its connection destination. No connection is initiated here; the subsequent Connect request owns it. Reject non-TCP, already connected, unbound, or mismatched-family sockets. On failure retain nothing and drop the rejected transport.
Sourcefn attach_tcp_connect_unbound(
&mut self,
_handle: Handle,
_transport: Self::Detached,
_destination: SocketAddr,
) -> Result<(), Error>
fn attach_tcp_connect_unbound( &mut self, _handle: Handle, _transport: Self::Detached, _destination: SocketAddr, ) -> Result<(), Error>
Adopt an unbound TCP socket and install its connection destination. Unix must not bind before Connect; Windows binds inside adoption for ConnectEx. Reject bound/non-TCP/mismatched-family transports and retain nothing on failure. Subsequent Connect owns completion and cancellation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".