Skip to main content

Bar

Struct Bar 

Source
pub struct Bar<'a> {
    pub at: &'a str,
    pub value: usize,
    pub reading: Option<&'a str>,
    pub note: Option<&'a str>,
}
Expand description

One magnitude in a Chart, at its place on the axis.

Carries no axis of its own on purpose: a bar read against a maximum it states itself is a meter, and a run of those is not a chart.

Fields§

§at: &'a str

Where on the axis this sits: “Mar 3”, “Week 12”.

The position’s own name rather than an index, for the reason a pager’s jump carries its page number: what a chart shows is a window over a series, and an index into that window is not the point it names.

§value: usize

The magnitude, in the chart’s units, read against Chart::most.

§reading: Option<&'a str>

The magnitude as the app words it: “$42.10”.

Worded rather than derived because the units are the app’s. A renderer handed 4210 cannot know it is money, let alone which money.

§note: Option<&'a str>

A second fact about this bar, already worded: “3 sales”.

Worded for the reason reading is, plus one of its own: a count’s noun inflects with the count, and that is language rather than drawing.

Implementations§

Source§

impl<'a> Bar<'a>

Source

pub const fn at(at: &'a str) -> Self

A place on the axis, with no magnitude on it yet.

The magnitude arrives through of rather than as a second argument, and that is not stylistic: quasi-declare stages a constructor’s plain arguments all one way or all the other, so a constructor taking a place AND a magnitude would have the place standing in as a number. Split, the place is a value and of is a count, which is the same split a pager’s of makes and the reason it is spelled the same.

Source

pub const fn of(self, value: usize) -> Self

How far up the axis this bar reaches.

Source

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

How the app words this magnitude.

Source

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

A second fact about the bar, already worded.

Source

pub fn fraction(&self, chart: &Chart<'_>) -> f32

How far up the axis this bar reaches, 0.0 to 1.0, clamped.

For drawing, which is what a clamped number is good for, and for the two renderers that draw in cells and pixels rather than in CSS. An empty axis reads as 0.0 rather than dividing by zero.

A bar over Chart::most clamps, and unlike Meter that is not a fact being lost: most is the maximum of the bars, so a bar above it is an axis the app got wrong rather than an over-run worth drawing.

Trait Implementations§

Source§

impl<'a> Clone for Bar<'a>

Source§

fn clone(&self) -> Bar<'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 Bar<'a>

Source§

impl<'a> Debug for Bar<'a>

Source§

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

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

impl<'a> Eq for Bar<'a>

Source§

impl<'a> Hash for Bar<'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 Bar<'a>

Source§

fn eq(&self, other: &Bar<'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 Bar<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Bar<'a>

§

impl<'a> RefUnwindSafe for Bar<'a>

§

impl<'a> Send for Bar<'a>

§

impl<'a> Sync for Bar<'a>

§

impl<'a> Unpin for Bar<'a>

§

impl<'a> UnsafeUnpin for Bar<'a>

§

impl<'a> UnwindSafe for Bar<'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 = !

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.