From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/syn/tests/repo/progress.rs | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 third_party/rust/syn/tests/repo/progress.rs (limited to 'third_party/rust/syn/tests/repo/progress.rs') diff --git a/third_party/rust/syn/tests/repo/progress.rs b/third_party/rust/syn/tests/repo/progress.rs new file mode 100644 index 0000000000..28c8a44b12 --- /dev/null +++ b/third_party/rust/syn/tests/repo/progress.rs @@ -0,0 +1,37 @@ +use std::io::{Read, Result}; +use std::time::{Duration, Instant}; + +pub struct Progress { + bytes: usize, + tick: Instant, + stream: R, +} + +impl Progress { + pub fn new(stream: R) -> Self { + Progress { + bytes: 0, + tick: Instant::now() + Duration::from_millis(2000), + stream, + } + } +} + +impl Read for Progress { + fn read(&mut self, buf: &mut [u8]) -> Result { + let num = self.stream.read(buf)?; + self.bytes += num; + let now = Instant::now(); + if now > self.tick { + self.tick = now + Duration::from_millis(500); + errorf!("downloading... {} bytes\n", self.bytes); + } + Ok(num) + } +} + +impl Drop for Progress { + fn drop(&mut self) { + errorf!("done ({} bytes)\n", self.bytes); + } +} -- cgit v1.2.3