timely_communication/allocator/zero_copy/
stream.rs

1//! Abstractions over network streams.
2
3use std::io;
4use std::net::{TcpStream, Shutdown};
5#[cfg(unix)]
6use std::os::unix::net::UnixStream;
7
8/// An abstraction over network streams.
9pub trait Stream: Sized + Send + Sync + io::Read + io::Write {
10    /// Creates a new independently owned handle to the underlying stream.
11    fn try_clone(&self) -> io::Result<Self>;
12
13    /// Moves this stream into or out of nonblocking mode.
14    fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()>;
15
16    /// Shuts down the read, write, or both halves of this connection.
17    fn shutdown(&self, how: Shutdown) -> io::Result<()>;
18}
19
20impl Stream for TcpStream {
21    fn try_clone(&self) -> io::Result<Self> {
22        self.try_clone()
23    }
24
25    fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
26        self.set_nonblocking(nonblocking)
27    }
28
29    fn shutdown(&self, how: Shutdown) -> io::Result<()> {
30        self.shutdown(how)
31    }
32}
33
34#[cfg(unix)]
35impl Stream for UnixStream {
36    fn try_clone(&self) -> io::Result<Self> {
37        self.try_clone()
38    }
39
40    fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
41        self.set_nonblocking(nonblocking)
42    }
43
44    fn shutdown(&self, how: Shutdown) -> io::Result<()> {
45        self.shutdown(how)
46    }
47}