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
impl Percentage
Sourcepub fn new<T: NumCast>(value: T) -> Percentage
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
impl Add<Percentage> for f32
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for f64
impl Add<Percentage> for f64
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for i128
impl Add<Percentage> for i128
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for i16
impl Add<Percentage> for i16
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for i32
impl Add<Percentage> for i32
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for i64
impl Add<Percentage> for i64
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for i8
impl Add<Percentage> for i8
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for isize
impl Add<Percentage> for isize
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for u128
impl Add<Percentage> for u128
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for u16
impl Add<Percentage> for u16
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for u32
impl Add<Percentage> for u32
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for u64
impl Add<Percentage> for u64
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for u8
impl Add<Percentage> for u8
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add<Percentage> for usize
impl Add<Percentage> for usize
Source§type Output = Percentage
type Output = Percentage
The resulting type after applying the
+
operator.Source§impl Add for Percentage
impl Add for Percentage
Source§impl<T: NumCast> AddAssign<T> for Percentage
impl<T: NumCast> AddAssign<T> for Percentage
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the
+=
operation. Read moreSource§impl AddAssign for Percentage
impl AddAssign for Percentage
Source§fn add_assign(&mut self, rhs: Percentage)
fn add_assign(&mut self, rhs: Percentage)
Performs the
+=
operation. Read moreSource§impl Clone for Percentage
impl Clone for Percentage
Source§fn clone(&self) -> Percentage
fn clone(&self) -> Percentage
Returns a copy 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 Debug for Percentage
impl Debug for Percentage
Source§impl Default for Percentage
impl Default for Percentage
Source§fn default() -> Percentage
fn default() -> Percentage
Returns the “default value” for a type. Read more
Source§impl Display for Percentage
impl Display for Percentage
Source§impl Mul<Percentage> for f32
impl Mul<Percentage> for f32
Source§impl Mul<Percentage> for f64
impl Mul<Percentage> for f64
Source§impl Mul<Percentage> for i128
impl Mul<Percentage> for i128
Source§impl Mul<Percentage> for i16
impl Mul<Percentage> for i16
Source§impl Mul<Percentage> for i32
impl Mul<Percentage> for i32
Source§impl Mul<Percentage> for i64
impl Mul<Percentage> for i64
Source§impl Mul<Percentage> for i8
impl Mul<Percentage> for i8
Source§impl Mul<Percentage> for isize
impl Mul<Percentage> for isize
Source§impl Mul<Percentage> for u128
impl Mul<Percentage> for u128
Source§impl Mul<Percentage> for u16
impl Mul<Percentage> for u16
Source§impl Mul<Percentage> for u32
impl Mul<Percentage> for u32
Source§impl Mul<Percentage> for u64
impl Mul<Percentage> for u64
Source§impl Mul<Percentage> for u8
impl Mul<Percentage> for u8
Source§impl Mul<Percentage> for usize
impl Mul<Percentage> for usize
Source§impl Mul for Percentage
impl Mul for Percentage
Source§impl MulAssign<Percentage> for f32
impl MulAssign<Percentage> for f32
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for f64
impl MulAssign<Percentage> for f64
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for i128
impl MulAssign<Percentage> for i128
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for i16
impl MulAssign<Percentage> for i16
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for i32
impl MulAssign<Percentage> for i32
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for i64
impl MulAssign<Percentage> for i64
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for i8
impl MulAssign<Percentage> for i8
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for isize
impl MulAssign<Percentage> for isize
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for u128
impl MulAssign<Percentage> for u128
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for u16
impl MulAssign<Percentage> for u16
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for u32
impl MulAssign<Percentage> for u32
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for u64
impl MulAssign<Percentage> for u64
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for u8
impl MulAssign<Percentage> for u8
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign<Percentage> for usize
impl MulAssign<Percentage> for usize
Source§fn mul_assign(&mut self, rhs: Percentage)
fn mul_assign(&mut self, rhs: Percentage)
Performs the
*=
operation. Read moreSource§impl MulAssign for Percentage
impl MulAssign for Percentage
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*=
operation. Read moreSource§impl PartialEq for Percentage
impl PartialEq for Percentage
impl Copy for Percentage
impl StructuralPartialEq for Percentage
Auto Trait Implementations§
impl Freeze for Percentage
impl RefUnwindSafe for Percentage
impl Send for Percentage
impl Sync for Percentage
impl Unpin for Percentage
impl UnwindSafe for Percentage
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