pub struct ByteCounter<T: AsyncWrite> { /* private fields */ }
Expand description
An AsyncWrite which counts bytes written to the wrapped AsyncWrite.
let mut counter = ByteCounter::new(sink());
counter.write("this is a test".as_bytes()).await?;
assert_eq!(14, counter.byte_count());
§Note
The count is stored as a u128 and unchecked addition is use to increment the count which means wrapping a long running AsyncWrite may lead to an overflow.
Implementations§
Source§impl<T: AsyncWrite> ByteCounter<T>
impl<T: AsyncWrite> ByteCounter<T>
Sourcepub fn new(inner: T) -> Self
pub fn new(inner: T) -> Self
Returns a new ByteCounter wrapping the inner AsyncWrite, with the byte count initialised to 0.
Sourcepub fn byte_count(&self) -> u128
pub fn byte_count(&self) -> u128
Returns the current count of bytes written into the AsyncWrite.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the inner AsyncWrite, consuming this Self.
Trait Implementations§
Source§impl<T: AsyncWrite> AsyncWrite for ByteCounter<T>
impl<T: AsyncWrite> AsyncWrite for ByteCounter<T>
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
Attempt to write bytes from
buf
into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Attempt to flush the object, ensuring that any buffered data reach
their destination. Read more
Source§impl<T: Debug + AsyncWrite> Debug for ByteCounter<T>
impl<T: Debug + AsyncWrite> Debug for ByteCounter<T>
impl<'__pin, T: AsyncWrite> Unpin for ByteCounter<T>where
PinnedFieldsOf<__Origin<'__pin, T>>: Unpin,
Auto Trait Implementations§
impl<T> Freeze for ByteCounter<T>where
T: Freeze,
impl<T> RefUnwindSafe for ByteCounter<T>where
T: RefUnwindSafe,
impl<T> Send for ByteCounter<T>where
T: Send,
impl<T> Sync for ByteCounter<T>where
T: Sync,
impl<T> UnwindSafe for ByteCounter<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
Source§fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
Creates a future which will entirely flush this
AsyncWrite
. Read moreSource§fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
Creates a future which will entirely close this
AsyncWrite
.Source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
Creates a future which will write bytes from
buf
into the object. Read moreSource§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
Creates a future which will write bytes from
bufs
into the object using vectored
IO operations. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more