Skip to main content

base_scheduler/
socket_stream_reading.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::{BufferPool, BufferPooling, SocketOperation, SocketStreamReader};
5use std::io;
6
7/// 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.
8pub trait SocketStreamReading: SocketOperation + BufferPooling {
9    /// Retain the socket and reusable backend state without submitting a receive or allocating a payload pool. Owned reads initialize default storage lazily.
10    fn socket_stream_reader<'scheduler>(
11        &'scheduler self,
12        socket: &Self::Socket,
13    ) -> io::Result<impl SocketStreamReader<Buffer = <Self::Pool as BufferPool>::Buffer> + 'scheduler>
14    where
15        Self::Socket: 'static;
16
17    /// Construct a reader using the supplied pool for owned chunks. Borrowed reads do not acquire pool storage. Returned chunks retain their pool independently of the reader.
18    fn socket_stream_reader_with_pool<'scheduler>(
19        &'scheduler self,
20        socket: &Self::Socket,
21        pool: Self::Pool,
22    ) -> io::Result<impl SocketStreamReader<Buffer = <Self::Pool as BufferPool>::Buffer> + 'scheduler>
23    where
24        Self::Socket: 'static;
25}