Skip to main content

base_scheduler/
socket_stream_writing.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::{BufferPool, BufferPooling, IoBuf, SocketOperation, SocketStreamWriter};
5use std::io;
6
7/// 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.
8///
9/// The returned handle may borrow the scheduler, but never the temporary socket
10/// reference. It retains backend access independently, so the socket and handle
11/// can move together. Retire and drop handles before exclusively closing the socket.
12pub trait SocketStreamWriting: SocketOperation + BufferPooling {
13    /// Retain the socket and reusable backend state. Owned submissions accept this scheduler's pooled chunks, so the default reader and writer compose without choosing a buffer representation. Borrowed writes do not allocate a payload pool. Subsequent operations take only payloads and cancellation, never another scheduler.
14    fn socket_stream_writer<'scheduler>(
15        &'scheduler self,
16        socket: &Self::Socket,
17    ) -> io::Result<
18        impl SocketStreamWriter<Buffer = <Self::Pool as BufferPool>::Buffer>
19        + 'scheduler
20        + use<'scheduler, Self>,
21    >
22    where
23        Self::Socket: 'static;
24
25    /// Select another stable owner type, such as `Vec<u8>` or an application lease. This changes storage compatibility, not the writer's ordering or backend execution strategy.
26    fn socket_stream_writer_with_buffer<'scheduler, B: IoBuf>(
27        &'scheduler self,
28        socket: &Self::Socket,
29    ) -> io::Result<impl SocketStreamWriter<Buffer = B> + 'scheduler + use<'scheduler, B, Self>>
30    where
31        Self::Socket: 'static;
32}