Added example main() fn impl

TODO: Make `UniformBufferProvider<R>(n..)` generate buffers from `n` to DEFAULT_BUFFER_SIZE.

TODO: Make `UniformBufferProvider<R>(..n)` generate buffers from 0 (i.e. no buffering) to `n`.

Fortune for throttle's current commit: Half blessing − 半吉
master
Avril 3 years ago
parent 0a065ed2b6
commit 07c4817a53
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,8 +1,15 @@
use std::io;
mod conf;
mod prov;
mod stream;
fn main() {
println!("Hello, world!");
fn main() -> io::Result<()> {
let mut input = io::stdin().lock();
let mut output = stream::ThrottleAdaptor::new(prov::UniformThrottleProvider::from(prov::Duration::from_millis(5)..prov::Duration::from_millis(50)), prov::UniformBufferProvider::from(0usize..=10), io::stdout().lock());
let copied = io::copy(&mut input, &mut output)?;
if cfg!(debug_assertions) {
eprintln!("Copied {copied} bytes from input -{output:?}> output");
}
Ok(())
}

@ -96,6 +96,7 @@ impl<W: ?Sized + Write, T: ThrottleProvider, B: BufferProvider> Write for Thrott
write_buf_with_timeout(&mut self.stream, &mut timeout, buf)
}).try_fold(0usize, |a, b| b.map(|b| b + a))?
},
// Don't chunk buffer
_ => write_buf_with_timeout(&mut self.stream, &mut timeout, buf)?
})
//self.reader.read(buf)

Loading…
Cancel
Save