Skip to main content

Meter

Struct Meter 

Source
pub struct Meter<'a> {
    pub done: u32,
    pub total: u32,
    pub tone: Tone,
    pub label: Option<&'a str>,
}
Expand description

How much of a set is done.

Added 0.10.0. Nine sites across the two webview apps drew a bar and nothing here named one, so every described screen concatenated the two numbers into its heading text instead: “Subtasks 3/7”, “Time Tracking 45m tracked / 30m est, over”. Every fact survives that and the reading does not, which is the same loss RowPart::Tokens closed when a toned status badge became prose.

§Why a pair and not a percentage

Both numbers, not the percentage the apps compute from them. The percentage was the obvious shape and it had already been tried: goingson’s Task::time_progress divides, rounds, and then clamps to 100, which throws away the one case the bar exists to show — 45 minutes tracked against a 30-minute estimate. It carries a separate is_over_estimate boolean beside it to recover the fact the clamp dropped. A pair keeps the over-run without a companion flag, and percent is still one call away for a renderer that wants it.

The pair is also what the apps already have at every site. All seven determinate bars write the ratio into the accessible layer and never the percentage: title="3/7 subtasks", aria-label="3 of 7 subtasks completed", a milestone’s own 3/7 span. Given 43 nothing can recover “3 of 7”, so a percentage member would have made label mandatory at every call site, which is the concatenated text this member removes, moved one layer down.

§What this is not

The progress of an operation. Two of the nine sites are that — goingson’s focus timer, Balanced Breakfast’s feed fetch — and they get nothing here, on purpose. Both are imperative controllers over a live handle, driven by a tick or an event stream, and a description is built once and dropped. Holding one would mean growing a way to update a description between renders, which is a different feature. Readiness::Pending and a Notice::Toast carry the honest part.

The two cases are distinguishable in the markup rather than by taste: every determinate bar in both apps carries a tone, and neither operation bar carries one. Two codebases drew that line the same way without coordinating.

Fields§

§done: u32

How much is done. May exceed total, and that is the case worth drawing.

§total: u32

How much there is to do. Zero means there is no set, not that the set is complete.

§tone: Tone

What the proportion means right now.

Carried rather than derived, because no renderer can work it out. The same 90% is Tone::Success on a subtask rollup and Tone::Danger on a time estimate, and goingson picks between them from is_over_estimate, a fact about the data and not about the number.

§label: Option<&'a str>

What is being counted, if the bar says so: “subtasks”, “tasks”.

The noun, not the ratio. A renderer builds “3 of 7 subtasks” from this and the two numbers; handing it the assembled string would put the sentence order in the description, where a terminal at one line and a tooltip want different ones.

Implementations§

Source§

impl<'a> Meter<'a>

Source

pub const fn new(done: u32, total: u32) -> Self

A proportion with no tone and no label.

Source

pub const fn tone(self, tone: Tone) -> Self

What the proportion means.

Source

pub const fn label(self, label: &'a str) -> Self

What is being counted.

Source

pub const fn percent(&self) -> u8

How full the bar is, 0 to 100, clamped.

For drawing, which is the only thing a clamped number is good for. Ask overflowing before reporting it as a fact, or this is time_progress’s bug again with the clamp moved.

An empty set reads as 0. Nothing is done, because there is nothing to do and no bar to fill; the apps guard on the count before drawing at all.

Source

pub const fn overflowing(&self) -> bool

Whether more is done than there was to do.

The fact percent destroys, kept reachable so a renderer can mark the over-run rather than drawing a full bar and implying it landed exactly.

Source

pub const fn is_empty(&self) -> bool

Whether there is a set at all.

A meter over nothing is sayable on purpose, for the same reason a field with no options is: it is what an app with an unloaded count actually has, and a renderer that shows an empty bar says so on screen rather than dividing by zero.

Trait Implementations§

Source§

impl<'a> Clone for Meter<'a>

Source§

fn clone(&self) -> Meter<'a>

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<'a> Copy for Meter<'a>

Source§

impl<'a> Debug for Meter<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Meter<'a>

Source§

impl<'a> Hash for Meter<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for Meter<'a>

Source§

fn eq(&self, other: &Meter<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Meter<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Meter<'a>

§

impl<'a> RefUnwindSafe for Meter<'a>

§

impl<'a> Send for Meter<'a>

§

impl<'a> Sync for Meter<'a>

§

impl<'a> Unpin for Meter<'a>

§

impl<'a> UnsafeUnpin for Meter<'a>

§

impl<'a> UnwindSafe for Meter<'a>

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.