Trait AsyncWriteRent

Source
pub trait AsyncWriteRent {
    // Required methods
    fn write<T: IoBuf>(
        &mut self,
        buf: T,
    ) -> impl Future<Output = BufResult<usize, T>>;
    fn writev<T: IoVecBuf>(
        &mut self,
        buf_vec: T,
    ) -> impl Future<Output = BufResult<usize, T>>;
    fn flush(&mut self) -> impl Future<Output = Result<()>>;
    fn shutdown(&mut self) -> impl Future<Output = Result<()>>;
}
Expand description

The AsyncWriteRent trait provides asynchronous writing capabilities for structs that implement it.

It abstracts over the concept of writing bytes asynchronously to an underlying I/O object, which could be a file, socket, or any other byte-oriented stream. The trait also encompasses the ability to flush buffered data and to shut down the output stream cleanly.

Types implementing this trait are required to manage asynchronous I/O operations, allowing for non-blocking writes. This is particularly useful in scenarios where the object might need to interact with other asynchronous tasks without blocking the executor.

Required Methods§

Source

fn write<T: IoBuf>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Writes the contents of a buffer into this writer, returning the number of bytes written.

This function attempts to write the entire buffer buf, but the write may not fully succeed, and it might also result in an error. A call to write represents at most one attempt to write to the underlying object.

§Return

When this method returns (Ok(n), buf), it guarantees that n <= buf.len(). A return value of 0 typically indicates that the underlying object can no longer accept bytes and likely won’t be able to in the future, or that the provided buffer is empty.

§Errors

Each write call may result in an I/O error, indicating the operation couldn’t be completed. If an error occurs, no bytes from the buffer were written to the writer.

It is not an error if the entire buffer could not be written to this writer.

Source

fn writev<T: IoVecBuf>( &mut self, buf_vec: T, ) -> impl Future<Output = BufResult<usize, T>>

This function attempts to write the entire contents of buf_vec, but the write may not fully succeed, and it might also result in an error. The bytes will be written starting at the specified offset.

§Return

The method returns the result of the operation along with the same array of buffers passed as an argument. A return value of 0 typically indicates that the underlying file can no longer accept bytes and likely won’t be able to in the future, or that the provided buffer is empty.

§Errors

Each write call may result in an I/O error, indicating the operation couldn’t be completed. If an error occurs, no bytes from the buffer were written to the writer.

It is not considered an error if the entire buffer could not be written to this writer.

Source

fn flush(&mut self) -> impl Future<Output = Result<()>>

Flushes this output stream, ensuring that all buffered content is successfully written to its destination.

§Errors

An error occurs if not all bytes can be written due to I/O issues or if the end of the file (EOF) is reached.

Source

fn shutdown(&mut self) -> impl Future<Output = Result<()>>

Shuts down the output stream, ensuring that the value can be cleanly dropped.

Similar to [flush], all buffered data is written to the underlying stream. After this operation completes, the caller should no longer attempt to write to the stream.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl AsyncWriteRent for Vec<u8>

Source§

fn write<T: IoBuf>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn writev<T: IoVecBuf>( &mut self, buf_vec: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn flush(&mut self) -> impl Future<Output = Result<()>>

Source§

fn shutdown(&mut self) -> impl Future<Output = Result<()>>

Source§

impl<A: ?Sized + AsyncWriteRent> AsyncWriteRent for &mut A

Source§

fn write<T: IoBuf>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn writev<T: IoVecBuf>( &mut self, buf_vec: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn flush(&mut self) -> impl Future<Output = Result<()>>

Source§

fn shutdown(&mut self) -> impl Future<Output = Result<()>>

Source§

impl<T: ?Sized + AsyncWriteRent + Unpin> AsyncWriteRent for Box<T>

Source§

fn write<B: IoBuf>( &mut self, buf: B, ) -> impl Future<Output = BufResult<usize, B>>

Source§

fn writev<B: IoVecBuf>( &mut self, buf_vec: B, ) -> impl Future<Output = BufResult<usize, B>>

Source§

fn flush(&mut self) -> impl Future<Output = Result<()>>

Source§

fn shutdown(&mut self) -> impl Future<Output = Result<()>>

Source§

impl<W> AsyncWriteRent for Cursor<W>
where Cursor<W>: Write + Unpin,

Source§

fn write<T: IoBuf>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn writev<T: IoVecBuf>( &mut self, buf_vec: T, ) -> impl Future<Output = BufResult<usize, T>>

Source§

fn flush(&mut self) -> impl Future<Output = Result<()>>

Source§

fn shutdown(&mut self) -> impl Future<Output = Result<()>>

Implementors§