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>
impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> AsyncWriteConverse<W, T>
pub async fn with_inner<F: FnOnce(&W) -> R, R>(&self, f: F) -> R
Sourcepub async fn optimize_memory_usage(&mut self)
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>
impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> AsyncWriteConverse<W, T>
Sourcepub async fn ask(&mut self, message: T) -> Result<T, Error>
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 .await
ing both layers of .send(message)
.
Sourcepub async fn ask_timeout(
&mut self,
timeout: Duration,
message: T,
) -> Result<T, Error>
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 .await
ing both layers of .send_timeout(message)
.
Sourcepub async fn send(
&mut self,
message: T,
) -> Result<impl Future<Output = Result<T, Error>>, Error>
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 .await
ing 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.
Sourcepub async fn send_timeout(
&mut self,
timeout: Duration,
message: T,
) -> Result<impl Future<Output = Result<T, Error>>, Error>
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
.await
ing the second layer is optional. You only need to .await
the second layer if you care about the
reply to your message.