Skip to main content

Stream

Trait Stream 

Source
pub trait Stream: Send + Sync {
    // Required methods
    fn context(&self) -> &Context;
    fn send_bytes<'life0, 'async_trait>(
        &'life0 self,
        data: Bytes,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn recv_bytes<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Bytes>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn close_send<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn close<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Stream trait for bidirectional RPC communication.

This trait provides message send/receive operations for streaming RPCs. The trait is object-safe by using bytes for the core methods.

§Implementation Notes

  • All methods are async and may block waiting for I/O or messages
  • send_bytes may return Error::Completed if close_send was already called
  • recv_bytes returns Error::StreamClosed when the remote closes
  • close cancels the context and releases all resources

Required Methods§

Source

fn context(&self) -> &Context

Returns the context for this stream.

The context can be used to check for cancellation or to get a cancellation token for cooperative cancellation.

Source

fn send_bytes<'life0, 'async_trait>( &'life0 self, data: Bytes, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends raw bytes on the stream.

§Errors
  • Error::Completed if close_send was already called
  • Error::StreamClosed if the connection was closed
  • Error::Io for transport errors
Source

fn recv_bytes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Bytes>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Receives raw bytes from the stream.

§Errors
  • Error::StreamClosed if the remote closed the stream
  • Error::Remote if the remote sent an error
  • Error::Cancelled if the context was cancelled
Source

fn close_send<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Closes the send side of the stream.

After calling this, send_bytes will return Error::Completed. The receive side remains open until the remote closes.

Source

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Closes both sides of the stream.

This cancels the context and releases all resources.

Implementations on Foreign Types§

Source§

impl<T: Stream + ?Sized> Stream for Box<T>

Source§

fn context(&self) -> &Context

Source§

fn send_bytes<'life0, 'async_trait>( &'life0 self, data: Bytes, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn recv_bytes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Bytes>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn close_send<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<T: Stream + ?Sized> Stream for Arc<T>

Source§

fn context(&self) -> &Context

Source§

fn send_bytes<'life0, 'async_trait>( &'life0 self, data: Bytes, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn recv_bytes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Bytes>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn close_send<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§