Struct AsyncWriteConverse

Source
pub struct AsyncWriteConverse<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> { /* private fields */ }
Expand description

Used to send messages to the connected peer. You may optionally receive replies to your messages as well.

You must drive the corresponding AsyncReadConverse in order to receive replies to your messages. You can do this either by driving the Stream implementation, or calling AsyncReadConverse::drive_forever.

Implementations§

Source§

impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> AsyncWriteConverse<W, T>

Source

pub async fn with_inner<F: FnOnce(&W) -> R, R>(&self, f: F) -> R

Source

pub async fn optimize_memory_usage(&mut self)

AsyncWriteConverse keeps a memory buffer for sending values which is the same size as the largest message that’s been sent. If the message size varies a lot, you might find yourself wasting memory space. This function will reduce the memory usage as much as is possible without impeding functioning. Overuse of this function may cause excessive memory allocations when the buffer needs to grow.

Source§

impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> AsyncWriteConverse<W, T>

Source

pub async fn ask(&mut self, message: T) -> Result<T, Error>

Send a message, and wait for a reply, with the default timeout. Shorthand for .awaiting both layers of .send(message).

Source

pub async fn ask_timeout( &mut self, timeout: Duration, message: T, ) -> Result<T, Error>

Send a message, and wait for a reply, up to timeout. Shorthand for .awaiting both layers of .send_timeout(message).

Source

pub async fn send( &mut self, message: T, ) -> Result<impl Future<Output = Result<T, Error>>, Error>

Sends a message to the peer on the other side of the connection. This returns a future wrapped in a future. You must .await the first layer to send the message, however .awaiting the second layer is optional. You only need to .await the second layer if you care about the reply to your message. Waits up to the default timeout for a reply.

Source

pub async fn send_timeout( &mut self, timeout: Duration, message: T, ) -> Result<impl Future<Output = Result<T, Error>>, Error>

Sends a message to the peer on the other side of the connection, waiting up to the specified timeout for a reply. This returns a future wrapped in a future. You must .await the first layer to send the message, however .awaiting the second layer is optional. You only need to .await the second layer if you care about the reply to your message.

Auto Trait Implementations§

§

impl<W, T> Freeze for AsyncWriteConverse<W, T>

§

impl<W, T> !RefUnwindSafe for AsyncWriteConverse<W, T>

§

impl<W, T> Send for AsyncWriteConverse<W, T>
where W: Send, T: Send,

§

impl<W, T> Sync for AsyncWriteConverse<W, T>
where W: Send, T: Send,

§

impl<W, T> Unpin for AsyncWriteConverse<W, T>

§

impl<W, T> !UnwindSafe for AsyncWriteConverse<W, 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.