1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pub use io::statistics::Bytes;
use std::io::{Error, Write};
#[derive(Default)]
pub struct LengthWriter {
bytes_written: usize,
}
impl LengthWriter {
pub fn new() -> Self {
LengthWriter { bytes_written: 0 }
}
pub fn len(&self) -> Bytes {
self.bytes_written.into()
}
}
impl Write for LengthWriter {
fn flush(&mut self) -> Result<(), Error> {
Ok(())
}
fn write(&mut self, buf: &[u8]) -> Result<usize, Error> {
self.bytes_written += buf.len();
Ok(buf.len())
}
}