pub struct MessageStream { /* private fields */ }Expand description
Represents an open subscribe stream.
This is a stream-like struct for serving messages to an application.
§Example
let mut stream = client
.subscribe("projects/my-project/subscriptions/my-subscription")
.build();
while let Some((m, h)) = stream.next().await.transpose()? {
println!("Received message m={m:?}");
h.ack();
}Implementations§
Source§impl MessageStream
impl MessageStream
Sourcepub async fn next(&mut self) -> Option<Result<(Message, Handler)>>
pub async fn next(&mut self) -> Option<Result<(Message, Handler)>>
Returns the next message received on this subscription.
§Example
while let Some((m, h)) = stream.next().await.transpose()? {
println!("Received message m={m:?}");
h.ack();
}Returns the message data along with a Handler to acknowledge (ack) the message.
If the underlying stream encounters a permanent error, an Error is
returned instead.
None represents the end of a stream, but in practice, the stream stays
open until it is cancelled or encounters a permanent error.
Sourcepub fn into_stream(
self,
) -> impl Stream<Item = Result<(Message, Handler)>> + Unpin
Available on crate feature unstable-stream only.
pub fn into_stream( self, ) -> impl Stream<Item = Result<(Message, Handler)>> + Unpin
unstable-stream only.Converts the MessageStream to a futures::Stream.
§Example
use futures::TryStreamExt;
let mut stream = stream.into_stream();
while let Some((m, h)) = stream.try_next().await? { /* ... */ }Trait Implementations§
Auto Trait Implementations§
impl Freeze for MessageStream
impl !RefUnwindSafe for MessageStream
impl Send for MessageStream
impl Sync for MessageStream
impl Unpin for MessageStream
impl UnsafeUnpin for MessageStream
impl !UnwindSafe for MessageStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request