Skip to main content

WireStream

Trait WireStream 

Source
pub trait WireStream {
    // Required methods
    fn poll_fill_into<P>(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        sink: &mut P,
        max: usize,
    ) -> Poll<Result<usize, Error>>
       where P: ParserSink;
    fn poll_write(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &[u8],
    ) -> Poll<Result<usize, Error>>;
    fn poll_flush(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Result<(), Error>>;
    fn poll_shutdown(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Result<(), Error>>;
}
Expand description

A bidirectional byte-level stream that fills a parser’s buffer.

Abstracts over plain TCP, TLS-wrapped TCP, and any user-provided transport (wrap in nexus_async_web::AsyncReadAdapter / NexusAsyncReadAdapter for the latter, depending on backend).

Implementations may take advantage of zero-copy paths when available — e.g. MaybeTls’s TLS variant feeds plaintext directly from rustls’s queue into the parser’s buffer, skipping the intermediate &mut [u8] copy that AsyncRead’s contract requires.

Required Methods§

Source

fn poll_fill_into<P>( self: Pin<&mut Self>, cx: &mut Context<'_>, sink: &mut P, max: usize, ) -> Poll<Result<usize, Error>>
where P: ParserSink,

Read bytes into sink.spare(). Returns the number of bytes actually delivered to the sink. Ok(0) indicates EOF.

max caps the bytes pulled in one call — useful for tail latency control. Implementations must respect it.

§Preconditions
  • max > 0
  • sink.spare() is non-empty

Implementations return Err(io::ErrorKind::InvalidInput) if either precondition is violated. With the preconditions met, Ok(0) unambiguously signals EOF — callers do not need to inspect sink state to distinguish “no buffer space” from “transport closed.”

Source

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>

Write buf to the transport. Returns the number of bytes accepted (may be less than buf.len()). Ok(0) may indicate the transport cannot accept more right now or that the underlying connection has been closed for writes — same semantics as tokio::io::AsyncWrite::poll_write. Implementors of new transports should mirror that contract.

Source

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>

Flush bytes previously written via poll_write to the transport. Returns Poll::Ready(Ok(())) once all buffered data has been pushed to the underlying socket. Mirrors tokio::io::AsyncWrite::poll_flush.

Source

fn poll_shutdown( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>

Shut down the write side of the transport. For TLS-bearing implementations, send close_notify first and flush before closing the underlying connection. Mirrors tokio::io::AsyncWrite::poll_shutdown.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§