Skip to main content

Stream

Trait Stream 

Source
pub trait Stream: Send + Sync {
    // Required methods
    fn read(&self, buf: &mut [u8]) -> NetResult<usize>;
    fn write_all(&self, buf: &[u8]) -> NetResult<()>;
    fn set_timeouts(&self, read_ms: Option<u32>, write_ms: Option<u32>);

    // Provided methods
    fn shutdown(&self) { ... }
    fn wait_readable(&self, _ms: u32) -> bool { ... }
    fn end_is_clean(&self) -> bool { ... }
}
Expand description

a byte stream HTTP runs over (shared between a reader and a writer: &self methods)

Required Methods§

Source

fn read(&self, buf: &mut [u8]) -> NetResult<usize>

up to buf.len() bytes; Ok(0) at the end

Source

fn write_all(&self, buf: &[u8]) -> NetResult<()>

Source

fn set_timeouts(&self, read_ms: Option<u32>, write_ms: Option<u32>)

timeouts for the following reads / writes (None: block)

Provided Methods§

Source

fn shutdown(&self)

no more writes from this side

Source

fn wait_readable(&self, _ms: u32) -> bool

whether bytes (or the end) can be read within ms

Source

fn end_is_clean(&self) -> bool

after read gave Ok(0): whether the peer ended the stream in order. TLS: only after its close_notify – a TCP end without one may be an attacker cutting a body that runs to the end of the connection (HTTP without a length). Plain streams: always

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Stream for TcpStream

Source§

fn read(&self, buf: &mut [u8]) -> NetResult<usize>

Source§

fn write_all(&self, buf: &[u8]) -> NetResult<()>

Source§

fn set_timeouts(&self, read_ms: Option<u32>, write_ms: Option<u32>)

Source§

fn shutdown(&self)

Source§

fn wait_readable(&self, ms: u32) -> bool

Implementors§