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

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.

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.

Get Before.

Return the before value if non-zero, otherwise None.

Get After.

Return the after value if non-zero, otherwise None.

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.

Percentage Difference (After < Before).

This is the same as BeforeAfter::less, but returns a percentage of the difference over before.

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.

Percentage Difference (After > Before).

This is the same as BeforeAfter::more, but returns a percentage of the difference over before.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.