PercentCalculus

Trait PercentCalculus 

Source
pub trait PercentCalculus<Rhs = Self> {
    // Required methods
    fn addpercent(self, rhs: Rhs) -> Self;
    fn subpercent(self, rhs: Rhs) -> Self;
    fn how_many(self, percent: Self) -> Self;
    fn change(self, new: Self) -> Self;
}
Expand description

Trait for performing percentage-based calculations.

This trait provides methods to add, subtract, and calculate percentages for numeric types, enabling common financial calculations.

Required Methods§

Source

fn addpercent(self, rhs: Rhs) -> Self

Adds a percentage to the value.

§Arguments
  • rhs - The percentage to add (e.g., 10.0 for 10%).
§Returns

The value increased by the given percentage.

Source

fn subpercent(self, rhs: Rhs) -> Self

Subtracts a percentage from the value.

§Arguments
  • rhs - The percentage to subtract (e.g., 10.0 for 10%).
§Returns

The value decreased by the given percentage.

Source

fn how_many(self, percent: Self) -> Self

Calculates the absolute value of a percentage.

§Arguments
  • percent - The percentage to calculate (e.g., 10.0 for 10%).
§Returns

The absolute value of the given percentage.

Source

fn change(self, new: Self) -> Self

Calculates the percentage change between two values.

§Arguments
  • new - The new value to compare with.
§Returns

The percentage change from the original value to the new value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl PercentCalculus for f64

Source§

fn addpercent(self, percent: Self) -> Self

Source§

fn subpercent(self, percent: Self) -> Self

Source§

fn how_many(self, percent: Self) -> Self

Source§

fn change(self, new: Self) -> Self

Implementors§