Struct fyi_msg::BeforeAfter
source · [−]pub struct BeforeAfter { /* private fields */ }
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
sourceimpl 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 fn less(&self) -> Option<NonZeroU64>
pub 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.
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 fn more(&self) -> Option<NonZeroU64>
pub 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.
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
sourceimpl Clone for BeforeAfter
impl Clone for BeforeAfter
sourcefn clone(&self) -> BeforeAfter
fn clone(&self) -> BeforeAfter
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for BeforeAfter
impl Debug for BeforeAfter
impl Copy for BeforeAfter
Auto Trait Implementations
impl RefUnwindSafe for BeforeAfter
impl Send for BeforeAfter
impl Sync for BeforeAfter
impl Unpin for BeforeAfter
impl UnwindSafe for BeforeAfter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more