Skip to main content

base_endpoint/
connect_endpoint.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use base_scheduler::{Cancellation, OperationResult};
5use std::future::Future;
6
7/// A reusable description of how to establish a connection. Consumers depend on this contract rather than DNS, addresses, or socket construction. `S` supplies explicit execution capabilities; the endpoint retains no scheduler and spawns no tasks.
8///
9/// Connection representation belongs to the implementation: a plain endpoint can return a scheduler socket, while a wrapper can return another transport. Errors preserve cooperative cancellation separately from I/O failure. Implementations must not retry cancellation as an ordinary connection failure.
10pub trait ConnectEndpoint<S: ?Sized>: Send + Sync {
11    /// The established transport, owned by the caller on success.
12    type Connection: Send;
13
14    /// Establish one connection. Futures are lazy. Await completion after requesting cooperative cancellation so implementation-owned asynchronous cleanup can finish. Dropping a future abandons it and provides ordinary resource destruction, not an asynchronous cleanup guarantee.
15    fn connect(
16        &self,
17        scheduler: &S,
18        cancellation: &Cancellation,
19    ) -> impl Future<Output = OperationResult<Self::Connection>> + Send;
20}