Skip to main content

SendStream

Struct SendStream 

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

Source

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.

Source

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.

Source

pub async fn ready(&self) -> Result<(), StreamError>

Waits until a message can be sent, see poll_ready().

Source

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.

Source

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.

Source

pub fn is_closed(&self) -> bool

Checks if the stream is closed, no more messages can be sent.

Source

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.

Source

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>

Source

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.

Trait Implementations§

Source§

impl<T> Clone for SendStream<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for SendStream<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Default for SendStream<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for SendStream<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for SendStream<T>

§

impl<T> !Send for SendStream<T>

§

impl<T> !Sync for SendStream<T>

§

impl<T> !UnwindSafe for SendStream<T>

§

impl<T> Forget for SendStream<T>

§

impl<T> Freeze for SendStream<T>

§

impl<T> Move for SendStream<T>

§

impl<T> Unpin for SendStream<T>

§

impl<T> UnsafeUnpin for SendStream<T>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRequest<T> for T

Source§

fn from(input: Request<T>) -> T

Build the argument from the decoded request.
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> MethodResult<T> for T

Source§

fn into_response(self) -> Result<Response<T>, ServerError>

Turn into the reply, or the error the call ends with. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V