Skip to main content

ServerStream

Struct ServerStream 

Source
pub struct ServerStream<B, RespView> { /* private fields */ }
Expand description

Response from a server-streaming RPC.

A server-streaming RPC response.

Provides incremental access to response messages as they arrive from the server. Messages are decoded one at a time from the HTTP response body using the message() method. Trailing metadata and errors (from the Connect END_STREAM envelope) become available after the message stream is exhausted.

§Example

let mut stream = call_server_stream(&transport, &config, "svc", "method", req, CallOptions::default()).await?;
println!("headers: {:?}", stream.headers());
while let Some(msg) = stream.message().await? {
    println!("got message: {:?}", msg);
}
if let Some(trailers) = stream.trailers() {
    println!("trailers: {:?}", trailers);
}

Implementations§

Source§

impl<B, RespView> ServerStream<B, RespView>
where B: Body<Data = Bytes> + Unpin, B::Error: Display, RespView: MessageView<'static> + Send, RespView::Owned: Message + DeserializeOwned,

Source

pub fn headers(&self) -> &HeaderMap

Returns the response headers.

Source

pub async fn message( &mut self, ) -> Result<Option<OwnedView<RespView>>, ConnectError>

Fetch the next message from the stream.

Returns Ok(Some(msg)) for each message, Ok(None) when the stream ends, or Err(...) on protocol/decode/deadline errors.

If a deadline was set on this call (via CallOptions::timeout or ClientConfig::default_timeout), each message() poll is bounded by it — gRPC deadline semantics are whole-call, so a hung server won’t block indefinitely (matching grpc-java and connect-go).

After this returns Ok(None), trailers() and error() become available.

Source

pub fn trailers(&self) -> Option<&HeaderMap>

Returns the trailing metadata, if available.

Only populated after message() returns Ok(None).

Source

pub fn error(&self) -> Option<&ConnectError>

Returns the trailing error from the END_STREAM envelope, if any.

Only populated after message() returns Ok(None).

Trait Implementations§

Source§

impl<B, RespView> Debug for ServerStream<B, RespView>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B, RespView> Freeze for ServerStream<B, RespView>
where B: Freeze,

§

impl<B, RespView> !RefUnwindSafe for ServerStream<B, RespView>

§

impl<B, RespView> Send for ServerStream<B, RespView>
where B: Send, RespView: Send,

§

impl<B, RespView> Sync for ServerStream<B, RespView>
where B: Sync, RespView: Sync,

§

impl<B, RespView> Unpin for ServerStream<B, RespView>
where B: Unpin, RespView: Unpin,

§

impl<B, RespView> UnsafeUnpin for ServerStream<B, RespView>
where B: UnsafeUnpin,

§

impl<B, RespView> !UnwindSafe for ServerStream<B, RespView>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more