pub enum Percentage<T> {
Fraction(Fraction<T>),
Points(Points<T>),
}Expand description
Percentage type that tracks whether the intenal value represents percentage points or a fractional part.
Variants§
Implementations§
Source§impl<T> Percentage<T>where
T: Number,
impl<T> Percentage<T>where
T: Number,
Sourcepub const fn from_fraction(fraction: T) -> Self
pub const fn from_fraction(fraction: T) -> Self
Construct a Percentage from a fractional value
Sourcepub const fn from_points(points: T) -> Self
pub const fn from_points(points: T) -> Self
Construct a Percentage from a percentage points value
Sourcepub fn to_fraction(self) -> T
pub fn to_fraction(self) -> T
Obtain the fractional representation of the Percentage
Sourcepub fn to_points(self) -> T
pub fn to_points(self) -> T
Obtain the points representation of the Percentage
Sourcepub fn to_fraction_mut(&mut self) -> &mut T
pub fn to_fraction_mut(&mut self) -> &mut T
Mutate the inner value as a fraction
Sourcepub fn to_points_mut(&mut self) -> &mut T
pub fn to_points_mut(&mut self) -> &mut T
Mutate the inner value as points
Sourcepub fn update_fraction(&mut self, f: impl FnOnce(T) -> T)
pub fn update_fraction(&mut self, f: impl FnOnce(T) -> T)
In-place update the inner value as a fraction
Sourcepub fn update_points(&mut self, f: impl FnOnce(T) -> T)
pub fn update_points(&mut self, f: impl FnOnce(T) -> T)
In-place update the inner value as points
Sourcepub fn apply_to(self, other: T) -> T
pub fn apply_to(self, other: T) -> T
Compute the quantity that represents the percentage of other
Sourcepub fn gain_loss(final_value: T, initial_value: T) -> Option<Self>
pub fn gain_loss(final_value: T, initial_value: T) -> Option<Self>
Compute the percentage gained or lost between the initial and final value.
Sourcepub fn part_of_the_whole(part: T, whole: T) -> Option<Self>
pub fn part_of_the_whole(part: T, whole: T) -> Option<Self>
Compute the percentage of the whole represented by the part
Trait Implementations§
Source§impl<T> Add for Percentage<T>where
T: Number,
impl<T> Add for Percentage<T>where
T: Number,
Source§impl<T: Clone> Clone for Percentage<T>
impl<T: Clone> Clone for Percentage<T>
Source§fn clone(&self) -> Percentage<T>
fn clone(&self) -> Percentage<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Debug for Percentage<T>where
T: Debug,
impl<T> Debug for Percentage<T>where
T: Debug,
Source§impl<T> Display for Percentage<T>
impl<T> Display for Percentage<T>
Source§impl<T> PartialEq for Percentage<T>where
T: Number,
impl<T> PartialEq for Percentage<T>where
T: Number,
Source§impl<T> PartialOrd for Percentage<T>where
T: Number,
impl<T> PartialOrd for Percentage<T>where
T: Number,
Source§impl<T> Sub for Percentage<T>where
T: Number,
impl<T> Sub for Percentage<T>where
T: Number,
impl<T: Copy> Copy for Percentage<T>
Auto Trait Implementations§
impl<T> Freeze for Percentage<T>where
T: Freeze,
impl<T> RefUnwindSafe for Percentage<T>where
T: RefUnwindSafe,
impl<T> Send for Percentage<T>where
T: Send,
impl<T> Sync for Percentage<T>where
T: Sync,
impl<T> Unpin for Percentage<T>where
T: Unpin,
impl<T> UnwindSafe for Percentage<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more