BufferedWrite

Struct BufferedWrite 

Source
pub struct BufferedWrite<'buf, T: Write> { /* private fields */ }
Expand description

A buffered Write

The BufferedWrite will write into the provided buffer to avoid small writes to the inner writer.

Implementations§

Source§

impl<'buf, T: Write> BufferedWrite<'buf, T>

Source

pub fn new(inner: T, buf: &'buf mut [u8]) -> Self

Create a new buffered writer

Source

pub fn new_with_data(inner: T, buf: &'buf mut [u8], written: usize) -> Self

Create a new buffered writer with a pre-polulated buffer

Source

pub fn is_empty(&self) -> bool

Get whether there are any bytes currently buffered

Source

pub fn written(&self) -> usize

Get the number of bytes that are currently buffered but not yet written to the inner writer

Source

pub fn clear(&mut self)

Clear the currently buffered, written bytes

Source

pub fn bypass(&mut self) -> Result<&mut T, BypassError>

Get the inner writer if there are no currently buffered, written bytes

Source

pub fn bypass_with_buf(&mut self) -> Result<(&mut T, &mut [u8]), BypassError>

Get the inner writer if there are no currently buffered, written bytes, and rent the buffer

Source

pub fn split(&mut self) -> (&mut T, &mut [u8], usize)

Split the writer to get the inner components

Source

pub fn release(self) -> T

Release and get the inner writer

Trait Implementations§

Source§

impl<T: Write> ErrorType for BufferedWrite<'_, T>

Source§

type Error = <T as ErrorType>::Error

Error type of all the IO operations on this type.
Source§

impl<T: Read + Write> Read for BufferedWrite<'_, T>

Source§

async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
Source§

impl<T: Write> Write for BufferedWrite<'_, T>

Source§

async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
Source§

async fn flush(&mut self) -> Result<(), Self::Error>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Source§

async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more

Auto Trait Implementations§

§

impl<'buf, T> Freeze for BufferedWrite<'buf, T>
where T: Freeze,

§

impl<'buf, T> RefUnwindSafe for BufferedWrite<'buf, T>
where T: RefUnwindSafe,

§

impl<'buf, T> Send for BufferedWrite<'buf, T>
where T: Send,

§

impl<'buf, T> Sync for BufferedWrite<'buf, T>
where T: Sync,

§

impl<'buf, T> Unpin for BufferedWrite<'buf, T>
where T: Unpin,

§

impl<'buf, T> !UnwindSafe for BufferedWrite<'buf, 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.