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,
impl<B, RespView> ServerStream<B, RespView>where
B: Body<Data = Bytes> + Unpin,
B::Error: Display,
RespView: MessageView<'static> + Send,
RespView::Owned: Message + DeserializeOwned,
Sourcepub async fn message(
&mut self,
) -> Result<Option<OwnedView<RespView>>, ConnectError>
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.
Sourcepub fn trailers(&self) -> Option<&HeaderMap>
pub fn trailers(&self) -> Option<&HeaderMap>
Returns the trailing metadata, if available.
Only populated after message() returns Ok(None).
Sourcepub fn error(&self) -> Option<&ConnectError>
pub fn error(&self) -> Option<&ConnectError>
Returns the trailing error from the END_STREAM envelope, if any.
Only populated after message() returns Ok(None).