Skip to main content

OverallEstimator

Struct OverallEstimator 

Source
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

Source

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).
Source

pub fn with_rates(self, rates: PhaseRates) -> Self

Use rates to size phases that have not started.

Source

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.

Source

pub fn set(&mut self, current: u64)

The current phase reached current units.

Source

pub fn inc(&mut self, units: u64)

The current phase advanced by units.

Source

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.

Source

pub fn finish(&mut self, _at: Duration)

The current phase finished at at.

Source

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).

Trait Implementations§

Source§

impl Clone for OverallEstimator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OverallEstimator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.