Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/syn-2.0.119/tests/repo/progress.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / syn-2.0.119 / tests / repo / progress.rs` 37 lines ยท 839 bytes Raw Blame History 1 use std::io::{Read, Result}; 2 use std::time::{Duration, Instant}; 3 4 pub struct Progress { 5 bytes: usize, 6 tick: Instant, 7 stream: R, 8 } 9 10 impl Progress { 11 pub fn new(stream: R) -> Self { 12 Progress { 13 bytes: 0, 14 tick: Instant::now() + Duration::from_secs(2), 15 stream, 16 } 17 } 18 } 19 20 impl Read for Progress { 21 fn read(&mut self, buf: &mut [u8]) -> Result { 22 let num = self.stream.read(buf)?; 23 self.bytes += num; 24 let now = Instant::now(); 25 if now > self.tick { 26 self.tick = now + Duration::from_millis(500); 27 errorf!("downloading... {} bytes\n", self.bytes); 28 } 29 Ok(num) 30 } 31 } 32 33 impl Drop for Progress { 34 fn drop(&mut self) { 35 errorf!("done ({} bytes)\n", self.bytes); 36 } 37 }