[−][src]Trait gwasm_api::ProgressUpdate
Trait specifying the required interface for an object tracking the computation's progress
Note that progress is tracked via active polling thus it might be prudent to store the value of current progress in the struct implementing the trait and update it only when the new reported progress value has actually risen (see Example: ProgressBar).
Example: simple tracker
use gwasm_api::ProgressUpdate; struct SimpleTracker; impl ProgressUpdate for SimpleTracker { fn update(&mut self, progress: f64) { println!("Current progress = {}", progress); } }
Example: ProgressBar
use gwasm_api::ProgressUpdate; use indicatif::ProgressBar; struct ProgressBarTracker { bar: ProgressBar, progress: f64, } impl ProgressBarTracker { fn new(num_subtasks: u64) -> Self { Self { bar: ProgressBar::new(num_subtasks), progress: 0.0, } } } impl ProgressUpdate for ProgressBarTracker { fn update(&mut self, progress: f64) { if progress > self.progress { self.progress = progress; self.bar.inc(1); } } fn start(&mut self) { self.bar.inc(0); } fn stop(&mut self) { self.bar.finish_and_clear() } }
Required methods
Loading content...Provided methods
fn start(&mut self)
Called when progress updates started
fn stop(&mut self)
Called when progress updates finished