Expand description
Explicit, runtime-independent scheduler capabilities for protocol libraries.
Applications choose an execution environment; libraries ask for the operations they need. This crate defines the interface and runtime-independent support such as Cancellation and HeapBufferPool. It contains no executor, reactor, operating-system I/O implementation, or runtime adapter; companion crates such as base-scheduler-direct, base-scheduler-tokio, and base-scheduler-native provide those.
§Socket and file I/O
Construct a handle from the scheduler once, then pass a Cancellation to each operation. A handle keeps its scheduler for its whole lifetime, and protocol code can retain it alongside parser state.
| Factory | Handle | Operations |
|---|---|---|
SocketStreamReading | SocketStreamReader | read returns an owned chunk; read_into and read_vectored use borrowed parser storage. |
SocketStreamWriting | SocketStreamWriter | write and write_vectored make borrowed transfers; submit accepts owned output that progresses independently, and flush waits for all accepted bytes. |
SocketPacketReading | SocketPacketReader | read returns an owned message with source metadata; borrowed forms fill caller storage and report truncation. |
SocketPacketWriting | SocketPacketWriter | Send one packet from borrowed scalar/vector storage or an owned buffer, with an optional destination. |
FileReading | FileReader | Owned-buffer read at the OS cursor, or read_at an explicit offset. |
FileWriting | FileWriter | Owned-buffer write at the OS cursor, write_at an explicit offset, or write_all. |
Use one handle per sequential execution, with separate readers and writers for concurrent tasks. Borrowed-only readers allocate no receive pool; owned reads initialize a default pool lazily, or use a shared BufferPool passed to socket_stream_reader_with_pool or socket_packet_reader_with_pool. Retained chunks can freeze into immutable views that move between tasks. File handles have no private logical position, and file operations return the original buffer owner alongside the BufferResult.
Call close().await on each handle before dropping it and exclusively closing its resource, flushing successful stream output first. Dropping a handle is not an awaited cleanup barrier.
§Other capabilities
Protocol libraries require the individual capabilities they use; there is no universal scheduler trait. Socket and file lifecycle operations are separate capabilities, such as SocketOpen, SocketBind, SocketListen, SocketConnect, SocketAccept, FileOpen, FileStat, FileSync, SocketClose, and FileClose.
| Capability | Contract |
|---|---|
Clock | Monotonic observations, cancellable relative or absolute waits, and operation timeouts. |
Timers | Experimental reusable timer state for repeated deadline waits. |
Spawn | Task dispatch with implementation-associated, owning completion handles. |
Blocking | Bounded admission of owned synchronous work. |
ProcessWait | Individual child and Unix process-group status waits with cooperative cancellation. |
PipeReading, PipeWriting | Unix adoption of owned pipe descriptors, such as child process standard streams, as sequential readers and writers. |
Signals | Notification subscriptions with implementation-associated guards and signal identifiers. |
BufferPooling | Shareable bounded storage with retained immutable views and cancellable capacity waits. |
| Extensions | Typed socket options (SocketGetOption, SocketSetOption), AddressResolution, SocketRegistration, FileAdvice, and FileAllocate. |
Operation futures use static dispatch and are Send; no boxed future or runtime-selection feature is required. Spawned futures and outputs are Send + 'static.
Cancellation is a cooperative signal: clones share state, children inherit ancestor cancellation, and dropping a signal does not cancel it. Pre-cancellation prevents submission, successful progress can win a concurrent request, and cancellation does not roll back transferred bytes or cursor changes. A task handle owns its execution: await it to observe completion, or drop it to request destruction after any active poll returns. Keep the scheduler and its drivers alive while accepted work retires.
See the I/O usage guide, interface reference, design and behavioral contracts, and runnable examples.
Structs§
- Address
Hints - Typed hints passed to the resolver. Defaults request either IP family, any socket type/protocol, and no flags.
- Address
Info - An owned IP endpoint and its socket creation parameters. Obtain its domain with
SocketDomain::from(info.address); pass its type and protocol directly tosocket_open. - Address
Resolve Error - Resolver-specific details stored inside
OperationError::Io. Recover this value withio_error.get_ref().and_then(|error| error.downcast_ref::<AddressResolveError>()). - Buffer
Lease - An exclusive writable pool lease. Its initialized length can be shortened after a read, without copying or borrowing the receiver. Drop returns storage to the pool; an I/O backend must retain this owner until its access retires. A lease keeps its backing slab alive even after the pool is dropped.
- Buffer
Pool Options - Usable payload capacity and alignment, independent of kernel registration strategy. Backends must satisfy these requirements or return an error; backend metadata and allocation padding may require additional memory.
- Buffer
Slice - An owned view into initialized storage. Dropping it drops its owner;
into_innerrecovers the complete buffer after an operation returns it. - Cancellation
- A runtime-independent, cooperative cancellation signal.
- Cancelled
- An operation observed a cooperative cancellation request.
- File
Options - Portable regular-file opening options. Fields are visible to alternative implementations, including simulated filesystems. Append mode is omitted: positioned writes must target the supplied offset.
- Frozen
Buffer - An immutable pool-backed chunk. Cloning or retaining a range shares its existing allocation; the final view returns the slot to the pool. Views keep the backing slab alive even after the pool is dropped, so parsers may choose to copy unusually long-lived fragments.
- Heap
Buffer Pool - A bounded, shareable collection of stable initialized slots in one contiguous slab. Construction reserves all payload storage; acquiring, freezing, slicing, and returning leases allocate no payload or reference-count wrappers.
- IoBuffers
- An owned scatter/gather package with I/O vectors prepared once at construction. The vector allocation and source owners are reused between operations; payload bytes are never copied.
- IoBuffers
Mut - An owned writable scatter/gather package with I/O vectors prepared once. Like
IoBuffers, it retains the complete source sequence and supports explicit advancement after retirement. - Owned
Socket Recv Message - A received payload owner paired with portable receive metadata. Other message implementations may retain their backend’s native metadata instead.
- Process
Wait Flags - Selection of child state changes. The default waits for termination.
- Process
Wait Result - One child’s status. Only a termination status means the child has exited.
- Socket
Keepalive - Boolean
SO_KEEPALIVE: enable or disable OS keepalive probes, using the system’s timing defaults. Probe intervals, counts, and application-level liveness policies are separate concerns. - Socket
Recv Flags - Portable input flags for socket receive operations.
- Socket
Recv Result - Metadata from one receive. Only
bytesbytes, spread across the buffers in order, were written; their initialized lengths remain unchanged. - Socket
Reuse Address - Boolean
SO_REUSEADDR. Set before binding when required by the application. - Socket
Send Flags - Portable input flags for socket send operations. Additional platform-specific flags belong in extension capabilities.
- TcpNo
Delay - Boolean
TCP_NODELAY: disable Nagle’s algorithm when true. Valid for TCP sockets; this does not promise one packet per write or confirmation of peer receipt.
Enums§
- Address
Resolve Error Kind - Portable classification of resolver failures. Native error codes remain available separately and are not errno values.
- Address
Service - A numeric port or a service name interpreted by the resolver’s service database. Named services can resolve differently for different transports.
- Advice
Mode - A file access or cache-management hint. Advice does not change the file’s contents, size, or cursor, and the operating system may ignore it.
- Allocation
Mode - How file-space allocation affects the logical file length.
- Blocking
Error - Blocking work could not be admitted. Job completion separately reports
TaskError. - File
Type - The portable classification of a filesystem object. Platform metadata can distinguish additional kinds, such as Unix devices, sockets, and FIFOs.
- Operation
Error - Cooperative cancellation is distinct from an operating-system error.
- Socket
Address - An IP endpoint, compatible with standard-library socket addresses. An internet socket address, either IPv4 or IPv6.
- Socket
Domain - The address family of an IP socket.
- Socket
Protocol - An explicit IP transport protocol. Pass
Nonetosocket_openfor the operating system default for the domain and type. - Socket
Type - The transport semantics requested when opening a socket.
- Spawn
Error - A task could not be registered with its scheduler.
- Sync
Mode - The file data and metadata requested by
FileSync::file_sync. A backend may provide stronger synchronization than requested. - Task
Error - A task ended without producing its normal output.
- Timeout
Error - Failure of a clock timeout, separate from the wrapped operation’s own output.
Traits§
- Address
Info Collection - An owned resolver result whose representation is chosen by the backend. Borrowed entry views remain valid only while the result is borrowed. Iteration must preserve candidate ordering, duplicates, and native socket parameters without requiring a copied collection or per-entry reference counts.
- Address
Info View - Portable accessors for a resolved IP endpoint and its socket creation parameters. A view may borrow a native resolver entry; accessing one field need not copy or normalize the others.
- Address
Resolution - Optional IP endpoint resolution, independent of socket creation and connection. Implementations may use a system resolver, an asynchronous resolver, or a deterministic table.
- Blocking
- Optional scheduler capability for owned synchronous work on blocking threads.
- Buffer
Pool - A bounded, shareable source of exclusively writable, stable receive storage. Clones share the same capacity. Completed buffers and their frozen views retain storage independently of pool handles, receivers, and polling threads; the final owner makes that slot reusable.
- Buffer
Pooling - Construct a backend-selected pool with portable ownership semantics. Applications choose the payload budget and alignment; implementations choose allocation and registration strategy. Pool construction performs no I/O on application resources.
- Clock
- Monotonic time and cooperative waits in one scheduler’s clock domain.
- File
Advice - Optional file advice capability, following Linux
posix_fadvisesemantics. - File
Allocate - Optional file-space reservation capability, with Linux
fallocatesemantics for ordinary allocation andKEEP_SIZE. - File
Close - Close exclusively owned file resources with completion or admission-only semantics.
- File
Metadata - Portable accessors for owned file status returned by
crate::FileStat::file_stat. Each backend chooses its representation, so native results need no eager field conversion and simulations need no OS resources. - File
Open - Create file resources through the chosen scheduler.
- File
Operation - Shared resource type for file operations provided by a scheduler.
- File
Reader - Scheduler-bound, sequential access to a file’s readable direction. Construct through
FileReading. Separate handles permit overlapping operations, but shared-cursor operations have no ordering guarantee across handles. - File
Reading - Construct a sequential file reader bound to this scheduler. Backends select the handle representation; protocols need no monitor or raw dispatch capabilities.
- File
Seek - Inspect or reposition a file resource’s shared cursor.
- File
Stat - Query owned metadata for an already-open file resource.
- File
Sync - Synchronize file contents and metadata through the chosen scheduler.
- File
Truncate - Change the logical length of an already-open file resource.
- File
Writer - Scheduler-bound, sequential access to a file’s writable direction. Construct through
FileWriting. Operations preserve the file’s shared OS cursor; separate handles do not coordinate writes through aliases. - File
Writing - Construct a sequential file writer bound to this scheduler. Backends select the handle representation; protocols need no monitor or raw dispatch capabilities.
- IoBuf
- Owned, initialized storage suitable for completion-based I/O.
- IoBuf
Mut - Owned writable storage. Operations fill its existing initialized length; they never expose uninitialized capacity or change the buffer length.
- IoBuf
Sequence - An owned sequence of buffers for scatter/gather I/O. The collection itself may move; each buffer’s byte storage must remain stable. Arrays avoid allocating a separate collection, and custom owners can retain pooled storage.
- IoBuf
Sequence Mut - An owned sequence of writable buffers. Receiving fills their initialized byte ranges without resizing them or replacing their owners.
- Notify
- A synchronous destination for a notification value.
- Pipe
Reader - Sequential, non-positional input from an adopted pipe, bound to its creating scheduler and owning its descriptor.
- Pipe
Reading - Adopt the readable end of an existing Unix pipe, such as
std::process::ChildStdout,ChildStderrorstd::io::PipeReader, as a scheduler-bound sequential reader. - Pipe
Writer - Sequential, non-positional output to an adopted pipe, bound to its creating scheduler and owning its descriptor.
- Pipe
Writing - Adopt the writable end of an existing Unix pipe, such as
std::process::ChildStdinorstd::io::PipeWriter, as a scheduler-bound sequential writer. - Process
Wait - Wait for a child process to change state without blocking an executor worker.
- Receive
Buffer - A uniquely writable completed receive that can become independently retained read-only storage. Backends choose the lease and shared representation; freezing consumes mutable access, and clones of the frozen owner keep its storage unavailable for reuse. Neither transition requires copying payload bytes.
- Signals
- Explicit signal subscriptions provided by a scheduler.
- Socket
Accept - Accept one connection from a listening socket.
- Socket
Address View - An IP endpoint exposed by an address representation chosen by its provider. A view can borrow native metadata or refer to an already materialized portable address. The contract specifies the endpoint, without prescribing storage, copying, or allocation costs.
- Socket
Bind - Bind an existing socket to a local IP address.
- Socket
Close - Consume and close an exclusively owned socket through the scheduler.
- Socket
Connect - Connect an existing socket to a peer IP address.
- Socket
GetOption - Read a typed socket option. See
SocketOptionsfor the shared option contract; the opposite operation is not required. - Socket
Listen - Put an existing socket into listening mode.
- Socket
Local Address - Inspect the local IP address of a socket.
- Socket
Open - Create an unbound IP socket through the scheduler.
- Socket
Operation - Shared resource type for socket operations provided by a scheduler. Implement this trait on the scheduler; all socket capabilities use this one associated type. No concrete OS descriptor or shared-ownership wrapper is required.
- Socket
Option - A typed socket-option identifier. This describes its value, not how an operating system represents or accesses it.
- Socket
Options - Convenience aggregate of
SocketGetOption<O>andSocketSetOption<O>, automatically implemented for schedulers providing both operations for an option. Generic consumers require only the options they use, such asS: SocketOptions<TcpNoDelay>. - Socket
Packet Reader - Sequential packet reception through a fixed execution service. Each read consumes at most one packet and preserves its sender and truncation metadata. Empty packets are messages, not EOF.
- Socket
Packet Reading - Construct sequential packet input bound to this scheduler. Backends choose the static reader and completed message representation without exposing their receive mechanism.
- Socket
Packet Writer - Sequential packet sends through a fixed execution service. Every write is one send attempt, including empty packets; it never splits a packet into separate sends.
Noneuses the connected peer. - Socket
Packet Writing - Construct sequential packet output bound to this scheduler. Separate reader and writer handles permit concurrent reception and sending; backends can choose their own static writer.
- Socket
Peer Address - Inspect the connected peer address of a socket.
- Socket
Recv Message - An owned received stream chunk or datagram, with backend-associated payload storage and metadata. The message may move between workers and outlive its receiver and scheduler. Its accessors describe contents and ownership, without prescribing allocation, copying, registration, or receive strategy.
- Socket
Recv Message Mut - A completed message with exclusively writable payload storage. Immutable receive implementations need not implement this capability.
- Socket
Registration - Optional interoperability with existing standard-library TCP resources. Streams and listeners become the same backend socket descriptor. Register once; the backend sets the nonblocking mode it needs. Do not change that mode through another handle. Simulated schedulers need not implement it.
- Socket
SetOption - Set a typed socket option. See
SocketOptionsfor the shared option contract; the opposite operation is not required. - Socket
Shutdown - Shut down one or both directions of a socket through the scheduler.
- Socket
Stream Reader - One sequential input lane on a stream socket, bound to its creating scheduler. Independent reader and writer handles may operate concurrently. Backend registration and worker migration are internal details; moving a handle never changes its scheduler.
- Socket
Stream Reading - Construct sequential stream input bound to this scheduler. Backends can substitute their own static reader while keeping protocol code independent of registration and receive mechanisms.
- Socket
Stream Writer - One ordered output lane on a stream socket, bound to its creating scheduler. Independent readers may operate concurrently. Separate writers or direct socket aliases do not share this handle’s ordering.
- Socket
Stream Writing - Construct sequential stream output bound to this scheduler. Backends select a static writer without requiring protocols to choose registration or output-progress mechanisms. Construction performs no writes and rejects non-stream sockets.
- Spawn
- The common spawning contract for schedulers and their handles.
- Timers
- Experimental reusable timer capability for the timer benchmark. This is not a settled public contract.
Functions§
- defer_
cancel - Notify protected work of cancellation and continue awaiting its completion.
Type Aliases§
- Buffer
Result - The operation result and original owned buffer, returned on success, error, or cancellation.
- Operation
Result - An operation’s result, preserving cancellation separately from I/O failure.