From 07c4817a536ab129e64d366364fcc15c431d4710 Mon Sep 17 00:00:00 2001 From: Avril Date: Sun, 17 Apr 2022 10:10:50 +0100 Subject: [PATCH] Added example main() fn impl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: Make `UniformBufferProvider(n..)` generate buffers from `n` to DEFAULT_BUFFER_SIZE. TODO: Make `UniformBufferProvider(..n)` generate buffers from 0 (i.e. no buffering) to `n`. Fortune for throttle's current commit: Half blessing − 半吉 --- src/main.rs | 11 +++++++++-- src/stream.rs | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index a0ed8f8..0fe39f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(()) } diff --git a/src/stream.rs b/src/stream.rs index bcda6fe..1da443b 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -96,6 +96,7 @@ impl 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)