pub struct Progress<D> { /* private fields */ }Expand description
A progress tracker that extends Counter with percentage completion tracking.
Progress<D> wraps a Counter<D> and adds tracking for expected total bytes
and derived metrics useful for progress reporting. Supports separate tracking
for read and write operations.
§Examples
use countio::Progress;
use std::io::Write;
let mut progress = Progress::with_expected_writer_bytes(Vec::new(), 1024);
progress.write_all(b"Hello").unwrap();
assert_eq!(progress.total_bytes(), 5);
assert_eq!(progress.expected_writer_bytes(), Some(1024));
assert!(progress.writer_percentage().unwrap() < 1.0);Implementations§
Source§impl<D> Progress<D>
impl<D> Progress<D>
Sourcepub const fn new(inner: D) -> Self
pub const fn new(inner: D) -> Self
Creates a new Progress<D> with unknown expected sizes.
§Examples
use countio::Progress;
let progress = Progress::new(Vec::<u8>::new());
assert_eq!(progress.expected_reader_bytes(), None);
assert_eq!(progress.expected_writer_bytes(), None);Sourcepub const fn with_expected_reader_bytes(inner: D, expected: usize) -> Self
pub const fn with_expected_reader_bytes(inner: D, expected: usize) -> Self
Creates a new Progress<D> with a known expected read size.
§Examples
use countio::Progress;
let progress = Progress::with_expected_reader_bytes(&b"hello"[..], 5);
assert_eq!(progress.expected_reader_bytes(), Some(5));
assert_eq!(progress.expected_writer_bytes(), None);Sourcepub const fn with_expected_writer_bytes(inner: D, expected: usize) -> Self
pub const fn with_expected_writer_bytes(inner: D, expected: usize) -> Self
Creates a new Progress<D> with a known expected write size.
§Examples
use countio::Progress;
let progress = Progress::with_expected_writer_bytes(Vec::<u8>::new(), 1024);
assert_eq!(progress.expected_reader_bytes(), None);
assert_eq!(progress.expected_writer_bytes(), Some(1024));Sourcepub const fn with_expected_bytes(
inner: D,
expected_reader_bytes: usize,
expected_writer_bytes: usize,
) -> Self
pub const fn with_expected_bytes( inner: D, expected_reader_bytes: usize, expected_writer_bytes: usize, ) -> Self
Creates a new Progress<D> with known expected read and write sizes.
§Examples
use countio::Progress;
use std::io::Cursor;
let cursor = Cursor::new(vec![0u8; 100]);
let progress = Progress::with_expected_bytes(cursor, 100, 50);
assert_eq!(progress.expected_reader_bytes(), Some(100));
assert_eq!(progress.expected_writer_bytes(), Some(50));Sourcepub const fn total_bytes(&self) -> u128
pub const fn total_bytes(&self) -> u128
Returns the total number of bytes processed (read + written).
Sourcepub const fn reader_bytes(&self) -> usize
pub const fn reader_bytes(&self) -> usize
Returns the number of bytes read.
Sourcepub const fn writer_bytes(&self) -> usize
pub const fn writer_bytes(&self) -> usize
Returns the number of bytes written.
Sourcepub const fn expected_reader_bytes(&self) -> Option<usize>
pub const fn expected_reader_bytes(&self) -> Option<usize>
Returns the expected number of bytes to read, if known.
Sourcepub const fn expected_writer_bytes(&self) -> Option<usize>
pub const fn expected_writer_bytes(&self) -> Option<usize>
Returns the expected number of bytes to write, if known.
Sourcepub const fn set_expected_reader_bytes(&mut self, expected: Option<usize>)
pub const fn set_expected_reader_bytes(&mut self, expected: Option<usize>)
Sets the expected number of bytes to read.
Sourcepub const fn set_expected_writer_bytes(&mut self, expected: Option<usize>)
pub const fn set_expected_writer_bytes(&mut self, expected: Option<usize>)
Sets the expected number of bytes to write.
Sourcepub fn reader_percentage(&self) -> Option<f64>
pub fn reader_percentage(&self) -> Option<f64>
Returns the read completion percentage (0.0 to 1.0) if expected read size is known.
§Examples
use countio::Progress;
use std::io::Read;
let data = b"Hello, World!";
let mut progress = Progress::with_expected_reader_bytes(&data[..], 13);
let mut buf = [0u8; 5];
progress.read(&mut buf).unwrap();
assert!((progress.reader_percentage().unwrap() - 0.3846).abs() < 0.001);Sourcepub fn writer_percentage(&self) -> Option<f64>
pub fn writer_percentage(&self) -> Option<f64>
Returns the write completion percentage (0.0 to 1.0) if expected write size is known.
§Examples
use countio::Progress;
use std::io::Write;
let mut progress = Progress::with_expected_writer_bytes(Vec::new(), 100);
progress.write_all(b"Hello").unwrap();
assert_eq!(progress.writer_percentage(), Some(0.05));Sourcepub fn into_inner(self) -> D
pub fn into_inner(self) -> D
Consumes the Progress<D> and returns the underlying I/O object.
Sourcepub const fn get_mut(&mut self) -> &mut D
pub const fn get_mut(&mut self) -> &mut D
Gets a mutable reference to the underlying I/O object.
Sourcepub const fn reset(&mut self)
pub const fn reset(&mut self)
Resets the byte counters to zero without affecting the underlying I/O object or the expected totals.
§Examples
use std::io::Write;
use countio::Progress;
let mut progress = Progress::with_expected_writer_bytes(Vec::new(), 100);
progress.write_all(b"Hello").unwrap();
assert_eq!(progress.writer_bytes(), 5);
assert_eq!(progress.writer_percentage(), Some(0.05));
progress.reset();
assert_eq!(progress.writer_bytes(), 0);
assert_eq!(progress.writer_percentage(), Some(0.0));
assert_eq!(progress.expected_writer_bytes(), Some(100)); // Expected preservedTrait Implementations§
Source§impl<R: AsyncBufRead + Unpin> AsyncBufRead for Progress<R>
Available on crate feature futures only.
impl<R: AsyncBufRead + Unpin> AsyncBufRead for Progress<R>
futures only.Source§impl<R: AsyncBufRead + Unpin> AsyncBufRead for Progress<R>
Available on crate feature tokio only.
impl<R: AsyncBufRead + Unpin> AsyncBufRead for Progress<R>
tokio only.Source§impl<R: AsyncRead + Unpin> AsyncRead for Progress<R>
Available on crate feature futures only.
impl<R: AsyncRead + Unpin> AsyncRead for Progress<R>
futures only.Source§impl<W: AsyncWrite + Unpin> AsyncWrite for Progress<W>
Available on crate feature futures only.
impl<W: AsyncWrite + Unpin> AsyncWrite for Progress<W>
futures only.Source§fn poll_write(
self: Pin<&mut Self>,
ctx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, ctx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>>
Source§impl<W: AsyncWrite + Unpin> AsyncWrite for Progress<W>
Available on crate feature tokio only.
impl<W: AsyncWrite + Unpin> AsyncWrite for Progress<W>
tokio only.Source§fn poll_write(
self: Pin<&mut Self>,
ctx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, ctx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>>
Source§fn poll_shutdown(
self: Pin<&mut Self>,
ctx: &mut Context<'_>,
) -> Poll<Result<()>>
fn poll_shutdown( self: Pin<&mut Self>, ctx: &mut Context<'_>, ) -> Poll<Result<()>>
Source§fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreSource§impl<R: BufRead> BufRead for Progress<R>
Available on crate feature std only.
impl<R: BufRead> BufRead for Progress<R>
std only.Source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Read methods, if empty. Read moreSource§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amount of additional bytes from the internal buffer as having been read.
Subsequent calls to read only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA byte) is reached, and append
them to the provided String buffer. Read moreSource§impl<R: Read> Read for Progress<R>
Available on crate feature std only.
impl<R: Read> Read for Progress<R>
std only.Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl<D: Seek> Seek for Progress<D>
Available on crate feature std only.
impl<D: Seek> Seek for Progress<D>
std only.Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Source§impl<W: Write> Write for Progress<W>
Available on crate feature std only.
impl<W: Write> Write for Progress<W>
std only.Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)