Struct fyi_msg::BeforeAfter
source · pub struct BeforeAfter { /* private fields */ }progress only.Expand description
Before and After.
This is a potentially useful companion to Progless that tracks an
arbitrary non-zero before and after state. It was created to make it easire
to track before/after file sizes from minification-type tasks, but it
doesn’t ascribe any particular meaning to the data it holds.
Examples
Usage is as simple as:
use fyi_msg::BeforeAfter;
let mut ba = BeforeAfter::start(123_u64);
// Do some stuff.
ba.stop(50_u64);Once before and after are set, you can use the getter methods BeforeAfter::before
and BeforeAfter::after to obtain the values.
For relative changes where after is expected to be smaller than before,
there is BeforeAfter::less and BeforeAfter::less_percent to obtain
the relative difference.
For cases where after is expected to be larger, use BeforeAfter::more
and BeforeAfter::more_percent instead.
Implementations§
source§impl BeforeAfter
impl BeforeAfter
sourcepub const fn start(before: u64) -> Self
pub const fn start(before: u64) -> Self
New Instance: Set Before.
This creates a new instance with the defined starting point.
A before value of 0_u64 is equivalent to None. The instance will
still be created, but the difference methods won’t return any values.
sourcepub fn stop(&mut self, after: u64)
pub fn stop(&mut self, after: u64)
Finish Instance: Set After.
This sets the after value of an existing instance, closing it out.
An after value of 0_u64 is equivalent to None, meaning the
difference methods won’t return any values.
sourcepub const fn before(&self) -> Option<NonZeroU64>
pub const fn before(&self) -> Option<NonZeroU64>
Get Before.
Return the before value if non-zero, otherwise None.
sourcepub const fn after(&self) -> Option<NonZeroU64>
pub const fn after(&self) -> Option<NonZeroU64>
Get After.
Return the after value if non-zero, otherwise None.
sourcepub const fn less(&self) -> Option<NonZeroU64>
pub const fn less(&self) -> Option<NonZeroU64>
Get Difference (After < Before).
If the after state is expected to be smaller than the before state,
return the difference. If either state is unset/zero, or after is
larger, None is returned.
Examples
use fyi_msg::BeforeAfter;
use std::num::NonZeroU64;
let ba = BeforeAfter::from((100_u64, 90_u64));
assert_eq!(ba.less(), NonZeroU64::new(10));sourcepub fn less_percent(&self) -> Option<f64>
pub fn less_percent(&self) -> Option<f64>
Percentage Difference (After < Before).
This is the same as BeforeAfter::less, but returns a percentage of
the difference over before.
sourcepub const fn more(&self) -> Option<NonZeroU64>
pub const fn more(&self) -> Option<NonZeroU64>
Get Difference (After > Before).
If the after state is expected to be larger than the before state,
return the difference. If either state is unset/zero, or after is
smaller, None is returned.
Examples
use fyi_msg::BeforeAfter;
use std::num::NonZeroU64;
let ba = BeforeAfter::from((100_u64, 130_u64));
assert_eq!(ba.more(), NonZeroU64::new(30));sourcepub fn more_percent(&self) -> Option<f64>
pub fn more_percent(&self) -> Option<f64>
Percentage Difference (After > Before).
This is the same as BeforeAfter::more, but returns a percentage of
the difference over before.
Trait Implementations§
source§impl Clone for BeforeAfter
impl Clone for BeforeAfter
source§fn clone(&self) -> BeforeAfter
fn clone(&self) -> BeforeAfter
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more