Skip to main content

marple_db/
progress.rs

1/// Receives byte-position updates from long-running transfers.
2///
3/// ```
4/// use marple_db::ProgressReporter;
5/// use std::sync::atomic::{AtomicU64, Ordering};
6///
7/// struct Counter(AtomicU64);
8///
9/// impl ProgressReporter for Counter {
10///     fn set_position(&self, position: u64) {
11///         self.0.store(position, Ordering::Relaxed);
12///     }
13///
14///     fn finish(&self) {}
15/// }
16/// ```
17pub trait ProgressReporter: Send + Sync + 'static {
18    /// Sets the current byte position.
19    fn set_position(&self, position: u64);
20
21    /// Marks the transfer as finished.
22    fn finish(&self);
23}
24
25/// Progress reporter that ignores all updates.
26#[derive(Clone, Copy, Debug, Default)]
27pub struct NoopProgress;
28
29impl ProgressReporter for NoopProgress {
30    fn set_position(&self, _position: u64) {}
31
32    fn finish(&self) {}
33}