Skip to main content

ResponseStream

Struct ResponseStream 

Source
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>

Source

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}");
}
Source

pub fn into_stream( self, ) -> impl Stream<Item = Result<Resp, Error>> + Send + Unpin

Available on crate feature unstable-stream only.

Converts the ResponseStream into an asynchronous Stream.

§Examples
let mut stream = stream.into_stream();
while let Some(item) = stream.next().await {
    let item = item?;
    println!("Received: {item}");
}

Trait Implementations§

Source§

impl<Resp> Debug for ResponseStream<Resp>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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.

§Examples

let (tx, rx) = mpsc::channel::<Result<String>>(16);
let receiver = ResponseStream::from(rx);
Source§

fn from(rx: Receiver<Result<Resp>>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Resp> !RefUnwindSafe for ResponseStream<Resp>

§

impl<Resp> !Sync for ResponseStream<Resp>

§

impl<Resp> !UnwindSafe for ResponseStream<Resp>

§

impl<Resp> Freeze for ResponseStream<Resp>
where ResponseState<Resp>: Freeze,

§

impl<Resp> Send for ResponseStream<Resp>
where ResponseState<Resp>: Send,

§

impl<Resp> Unpin for ResponseStream<Resp>
where ResponseState<Resp>: Unpin,

§

impl<Resp> UnsafeUnpin for ResponseStream<Resp>
where ResponseState<Resp>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.