pub struct SendStream<T> { /* private fields */ }Expand description
A stream of messages to the peer.
On the client, the request messages of a client-streaming or a bidi call. On the server, the response messages of a server-streaming or a bidi call.
The stream is shared, clones send on the same stream. Messages are sent
one at a time, send() waits for the one in progress. Concurrent sends
queue in the order their futures are first polled. Dropping the last
clone or calling close() ends the stream, the client
half-closes its request then. The server ends the stream when the handler
returns.
Implementations§
Source§impl<T> SendStream<T>
impl<T> SendStream<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a stream for a client-streaming call.
Pass it to the call, messages are sent once the call is opened,
send() waits until then.
Sourcepub fn poll_ready(&self, cx: &Context<'_>) -> Poll<Result<(), StreamError>>
pub fn poll_ready(&self, cx: &Context<'_>) -> Poll<Result<(), StreamError>>
Checks if a message can be sent.
Ready once the stream is open and no message is being sent, fails if
the stream is closed. Does not wait for flow-control capacity,
send() does. Readiness does not reserve a turn to send.
Sourcepub async fn ready(&self) -> Result<(), StreamError>
pub async fn ready(&self) -> Result<(), StreamError>
Waits until a message can be sent, see poll_ready().
Sourcepub fn close(&self)
pub fn close(&self)
Ends the stream, no more messages are sent.
A message being sent is completed first. On the server the stream ends when the handler returns.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancels the call, the h2 stream is reset with CANCEL.
On the client the response stream, or the reply of a
client-streaming call, fails with ClientError::StreamFailed and
CANCELLED.
Sourcepub fn header(&self, name: HeaderName, value: HeaderValue) -> bool
pub fn header(&self, name: HeaderName, value: HeaderValue) -> bool
Adds a response header, server side only.
Returns false if the headers are sent already, with the first message, or on the client.
Headers exceeding the peer’s limit reset the call with
INTERNAL_ERROR when the response starts.
Sourcepub fn trailer(&self, name: HeaderName, value: HeaderValue)
pub fn trailer(&self, name: HeaderName, value: HeaderValue)
Adds a response trailer, server side only.
The trailers are sent when the handler returns.
Source§impl<T: Message> SendStream<T>
impl<T: Message> SendStream<T>
Sourcepub async fn send(&self, msg: &T) -> Result<(), StreamError>
pub async fn send(&self, msg: &T) -> Result<(), StreamError>
Sends a message.
Waits until the stream is open, until a message being sent is
completed, and for flow-control capacity. A message over the size
limit fails with StreamError::Status and is not sent, the stream
stays usable. Other errors end the stream.
Dropping the future while it waits for its turn removes it from the queue without cancelling the call. Dropping the future while the message is written cancels the call.