percentage_rs

Struct Percentage

Source
pub struct Percentage(/* private fields */);
Expand description

Allows to calculate the percentage of any number

§Examples

§Create a Percentage with the default constructor

use percentage_rs::Percentage;
 
let p = Percentage::new(50);
assert!("50%" == format!("{}", p)); // the result is "50%"

§Create a Percentage with the trait Percent

use percentage_rs::Percent;
 
assert!(format!("{}", 50.percent()) == "50%"); // the result is "50%"

§Calculate the percentage

To do that you just need to multiply the percentage by your number

use percentage_rs::Percent;
 
let p = 1234*50.percent(); // 50% of 1234
assert!(p == 617.0 as f32); // the result is "617"

Implementations§

Source§

impl Percentage

Source

pub fn new<T: NumCast>(value: T) -> Percentage

Create a percentage with the given value into percen

Trait Implementations§

Source§

impl Add<Percentage> for f32

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for f64

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for i128

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for i16

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for i32

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for i64

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for i8

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for isize

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for u128

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for u16

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for u32

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for u64

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for u8

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Percentage> for usize

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Percentage) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Percentage

Source§

type Output = Percentage

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: NumCast> AddAssign<T> for Percentage

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl AddAssign for Percentage

Source§

fn add_assign(&mut self, rhs: Percentage)

Performs the += operation. Read more
Source§

impl Clone for Percentage

Source§

fn clone(&self) -> Percentage

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Percentage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Percentage

Source§

fn default() -> Percentage

Returns the “default value” for a type. Read more
Source§

impl Display for Percentage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Mul<Percentage> for f32

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for f64

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for i128

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for i16

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for i32

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for i64

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for i8

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for isize

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for u128

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for u16

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for u32

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for u64

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for u8

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Percentage> for usize

Source§

type Output = f32

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Percentage) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Percentage

Source§

type Output = Percentage

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<Percentage> for f32

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for f64

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for i128

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for i16

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for i32

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for i64

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for i8

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for isize

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for u128

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for u16

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for u32

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for u64

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for u8

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign<Percentage> for usize

Source§

fn mul_assign(&mut self, rhs: Percentage)

Performs the *= operation. Read more
Source§

impl MulAssign for Percentage

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl PartialEq for Percentage

Source§

fn eq(&self, other: &Percentage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Percentage

Source§

impl StructuralPartialEq for Percentage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.