pub struct ResponseStream<Resp> { /* private fields */ }Expand description
A handle for receiving inbound response items from a streaming RPC.
Typically, you receive a ResponseStream as the result of initiating a streaming RPC.
Unlike RequestSender, ResponseStream cannot be cloned and represents exclusive
ownership of the inbound stream. Call next to consume incoming messages
sequentially. Dropping the ResponseStream cancels the stream.
Enable the unstable-stream feature to convert this type into a Stream
via into_stream.
§Examples
while let Some(item) = stream.next().await {
let item = item?;
println!("Received: {item}");
}Implementations§
Source§impl<Resp> ResponseStream<Resp>
impl<Resp> ResponseStream<Resp>
Sourcepub async fn next(&mut self) -> Option<Result<Resp, Error>>
pub async fn next(&mut self) -> Option<Result<Resp, Error>>
Receives the next response message from the stream, or None if the stream has finished.
Returns Some(Err(e)) if a transport, server status, or deserialization error occurs.
Once an error or stream completion is reached, subsequent calls return None.
§Examples
while let Some(item) = stream.next().await {
let item = item?;
println!("Received: {item}");
}Trait Implementations§
Source§impl<Resp> Debug for ResponseStream<Resp>
impl<Resp> Debug for ResponseStream<Resp>
Source§impl<Resp> From<Receiver<Result<Resp, Error>>> for ResponseStream<Resp>where
Resp: Send + 'static,
Creates a ResponseStream from a Tokio mpsc::Receiver, useful for mocking in tests.
impl<Resp> From<Receiver<Result<Resp, Error>>> for ResponseStream<Resp>where
Resp: Send + 'static,
Creates a ResponseStream from a Tokio mpsc::Receiver, useful for mocking in tests.
§Examples
let (tx, rx) = mpsc::channel::<Result<String>>(16);
let receiver = ResponseStream::from(rx);