Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct CountingRead<'a, R: 'a + Read> {
- r: &'a mut R,
- count: usize,
- }
- impl<'a, R: 'a + Read> CountingRead<'a, R> {
- pub fn new(r: &'a mut R) -> Self {
- CountingRead { r: r, count: 0 }
- }
- pub fn count(&self) -> usize {
- self.count
- }
- pub fn reset(&mut self) {
- self.count = 0;
- }
- }
- impl<'a, R: 'a + Read> Read for CountingRead<'a, R> {
- fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
- match self.r.read(buf) {
- Ok(n) => {
- self.count += n;
- Ok(n)
- }
- err => err,
- }
- }
- }
Add Comment
Please, Sign In to add comment