pub struct Percent(pub f64);
Expand description
A value in percent (%).
Basic arithmetic is implemented for convenience, and the underlying f64 value is accessible as a tuple field.
§Example
use mendeleev::Percent;
use core::cmp::Ordering;
let value1 = Percent(1.0);
let value2 = Percent(2.0);
assert_eq!(value1.0, 1.0);
assert!(value1 < value2);
assert_eq!(value1.total_cmp(&value2), Ordering::Less);
assert_eq!(value1 + value2, Percent(3.0));
assert_eq!(value1 - value2, Percent(-1.0));
assert_eq!(value1 * 5.0, Percent(5.0));
assert_eq!(value1 / 4.0, Percent(0.25));
Tuple Fields§
§0: f64
Implementations§
Trait Implementations§
Source§impl Display for Percent
impl Display for Percent
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Displays the value along with the unit. Supports numeric formatting.
A space is added between the number and the unit, in accordance with the SI convention.
§Example
use mendeleev::Percent;
let value = Percent(1.2345);
assert_eq!(format!("{value:.1}"), "1.2 %");
Source§impl PartialOrd for Percent
impl PartialOrd for Percent
impl Copy for Percent
impl StructuralPartialEq for Percent
Auto Trait Implementations§
impl Freeze for Percent
impl RefUnwindSafe for Percent
impl Send for Percent
impl Sync for Percent
impl Unpin for Percent
impl UnwindSafe for Percent
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