base-endpoint
Reusable descriptions of how to connect and bind, inspired by Ruby's IO::Endpoint. Application code depends on endpoint contracts, while endpoint implementations handle resolution, socket creation, optional TLS and establishment through explicit base-scheduler capabilities.
Usage
Add the crate together with the scheduler interface it uses:
The API is experimental. This example binds a loopback listener and connects to it with the Native scheduler; add it with cargo add base-scheduler-native to run it:
use ;
use ;
use NativeScheduler;
Consumers can depend only on the connection contract, without naming TCP, TLS or a runtime:
use ConnectEndpoint;
use ;
async
See the API documentation for hostname resolution, composite fallback, binding, cancellation and cleanup, TLS composition, the optional rustls provider, and the plaintext stream contracts.
Releasing
Prepare a release with cargo bake cargo:version:patch (or minor, major, or bump --version X.Y.Z), commit it with a Release: vVERSION trailer, then run cargo bake cargo:release and open a pull request. After review and merge, GitHub Actions publishes the release when the configured crates-io environment approves it, then creates or updates the matching GitHub Release from releases.md. Follow the shared Releasing skill for the standard process.
Releases
See releases.md for the full release history.
v0.2.0
- Breaking: add the required
ReadableStream::try_read_into, which attempts one read now without waiting. Scheduler stream readers forward it toSocketStreamReader::try_read_into, and the rustls duplex reader drives its receive lane to read the socket immediately. Implementations outside this crate must add it; wrappers should forward it. - Breaking: depend on
base-scheduler 0.4, whose capability traits appear in this crate's public API.
v0.1.0
Initial release of the runtime-independent endpoints. Requires Rust 1.87 or later. The API is experimental.
- Provide separate
ConnectEndpointandBindEndpointcontracts, with associated connection and listener types, so consumers can abstract over establishment without a particular transport or runtime. - Connect and bind TCP over IPv4 and IPv6 with
AddressEndpointandHostEndpoint.CompositeEndpointcomposes any connect endpoints, and bind endpoints whose listeners the scheduler closes. Connection attempts fall back in order with fresh sockets and report the last error unless cancelled; binding is all-or-nothing and closes every socket it created on failure. - Describe plaintext byte I/O with
stream::{ReadableStream, WritableStream}, which scheduler stream handles implement directly. - Wrap endpoints with TLS through
tls::{TlsClientEndpoint, TlsServerEndpoint, TlsListener}over theTlsConnector,TlsAcceptorandTlsStreamcontracts.TlsSessionreports the negotiated ALPN protocol, and a failed handshake leaves aTlsListenerusable. - With the
rustlsfeature, provideRustlsConnector,RustlsAcceptorandRustlsConnection, with sequential reads and writes,shutdown,closeandabort.RustlsConnection::with_duplexruns an application with independent encrypted reader and writer handles, spawns no task, and joins lane retirement and socket closure before returning. A transport failure while it sendsclose_notifyis reported as that failure rather than as cancellation. - Depend on the published
base-scheduler 0.3interface; no concrete runtime is a production dependency.
See Also
- base-scheduler supplies the socket, stream and cancellation capabilities that endpoints use.
Contributing
Please open an issue or pull request on GitHub.