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_bytesmay returnError::Completedifclose_sendwas already calledrecv_bytesreturnsError::StreamClosedwhen the remote closesclosecancels the context and releases all resources
Required Methods§
Sourcefn context(&self) -> &Context
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.
Sourcefn 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 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::Completedifclose_sendwas already calledError::StreamClosedif the connection was closedError::Iofor transport errors
Sourcefn 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 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::StreamClosedif the remote closed the streamError::Remoteif the remote sent an errorError::Cancelledif the context was cancelled
Sourcefn 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_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.