pub struct OverallEstimator { /* private fields */ }Expand description
Combines per-phase progress into one overall estimate.
Phases under way are projected from their own measured pace; phases not
yet started are sized from the pack’s object and delta counts at typical
PhaseRates. The estimator never reads the clock: every call takes the
time elapsed since the operation began.
use std::time::Duration;
use grit_lib::progress::{OverallEstimator, ProgressPhase, ProgressUnit, ReceivedObjects};
let secs = Duration::from_secs;
let mut est = OverallEstimator::new(true);
est.start(ProgressPhase::ReceivingObjects, ProgressUnit::Bytes, None, secs(1));
est.received_objects(ReceivedObjects { received: 500, total: 1_000, deltas: 300 }, secs(3));
let now = est.estimate(secs(3)).unwrap();
assert!(now.fraction > 0.3 && now.fraction < 0.7);Implementations§
Source§impl OverallEstimator
impl OverallEstimator
Sourcepub fn new(checkout: bool) -> Self
pub fn new(checkout: bool) -> Self
Create an estimator with the default PhaseRates.
§Parameters
checkout: whether a work-tree checkout follows the transfer (true for a non-bare clone, false for a fetch).
Sourcepub fn with_rates(self, rates: PhaseRates) -> Self
pub fn with_rates(self, rates: PhaseRates) -> Self
Use rates to size phases that have not started.
Sourcepub fn start(
&mut self,
phase: ProgressPhase,
unit: ProgressUnit,
total: Option<u64>,
at: Duration,
)
pub fn start( &mut self, phase: ProgressPhase, unit: ProgressUnit, total: Option<u64>, at: Duration, )
A phase began at at, counting units towards total when known.
Starting a phase ends the previous one.
Sourcepub fn received_objects(&mut self, counts: ReceivedObjects, _at: Duration)
pub fn received_objects(&mut self, counts: ReceivedObjects, _at: Duration)
The pack being received now holds counts objects.
Sizes the later phases: the pack’s object total drives indexing, and the share of deltas seen so far projects how many will need resolving.
Sourcepub fn estimate(&mut self, at: Duration) -> Option<OverallEstimate>
pub fn estimate(&mut self, at: Duration) -> Option<OverallEstimate>
Overall progress at at, or None while there is not enough to go on
(before the transfer has reported any objects).