Struct icu::experimental::units::ratio::IcuRatio

source ·
pub struct IcuRatio(/* private fields */);
Expand description

A ratio type that uses BigInt as the underlying type.

Implementations§

source§

impl IcuRatio

source

pub fn from_big_ints(numerator: BigInt, denominator: BigInt) -> IcuRatio

Creates a new IcuRatio from the given numerator and denominator.

source

pub fn get_ratio(self) -> Ratio<BigInt>

Returns the current IcuRatio as a Ratio of BigInt.

source

pub fn abs(&self) -> IcuRatio

Returns the absolute value of the ratio.

source

pub fn two() -> IcuRatio

Returns a Ratio with value of 2.

source

pub fn ten() -> IcuRatio

Returns a Ratio with value of 10.

source

pub fn is_negative(&self) -> bool

Returns true if the ratio is negative.

Trait Implementations§

source§

impl Add<&IcuRatio> for &IcuRatio

source§

type Output = IcuRatio

The resulting type after applying the + operator.
source§

fn add(self, rhs: &IcuRatio) -> IcuRatio

Performs the + operation. Read more
source§

impl Add for IcuRatio

source§

type Output = IcuRatio

The resulting type after applying the + operator.
source§

fn add(self, rhs: IcuRatio) -> IcuRatio

Performs the + operation. Read more
source§

impl AddAssign for IcuRatio

source§

fn add_assign(&mut self, rhs: IcuRatio)

Performs the += operation. Read more
source§

impl Clone for IcuRatio

source§

fn clone(&self) -> IcuRatio

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 IcuRatio

source§

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

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

impl Div for IcuRatio

source§

type Output = IcuRatio

The resulting type after applying the / operator.
source§

fn div(self, rhs: IcuRatio) -> IcuRatio

Performs the / operation. Read more
source§

impl DivAssign for IcuRatio

source§

fn div_assign(&mut self, rhs: IcuRatio)

Performs the /= operation. Read more
source§

impl From<Ratio<BigInt>> for IcuRatio

source§

fn from(ratio: Ratio<BigInt>) -> IcuRatio

Converts to this type from the input type.
source§

impl From<u32> for IcuRatio

source§

fn from(value: u32) -> IcuRatio

Converts to this type from the input type.
source§

impl FromStr for IcuRatio

source§

fn from_str(number_str: &str) -> Result<IcuRatio, <IcuRatio as FromStr>::Err>

Converts a string representation of a ratio into an IcuRatio. Supported string formats include:

use core::str::FromStr;
use icu::experimental::units::ratio::IcuRatio;
use num_bigint::BigInt;
use num_rational::Ratio;
use num_traits::identities::Zero;

// Fractional notation
let ratio = IcuRatio::from_str("1/2").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::new(BigInt::from(1), BigInt::from(2)))
);

// Decimal notation
let ratio = IcuRatio::from_str("1.5").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::new(BigInt::from(3), BigInt::from(2)))
);

// Scientific notation
let ratio = IcuRatio::from_str("1.5E6").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::from_integer(BigInt::from(1500000)))
);

// Scientific notation with negative exponent
let ratio = IcuRatio::from_str("1.5E-6").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::new(BigInt::from(15), BigInt::from(10000000)))
);

// Scientific notation with commas
let ratio = IcuRatio::from_str("1,500E6").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::from_integer(BigInt::from(1500000000)))
);

// Integer notation
let ratio = IcuRatio::from_str("1").unwrap();
assert_eq!(ratio, IcuRatio::from(Ratio::from_integer(BigInt::from(1))));

// Fractional notation with exponent
let ratio = IcuRatio::from_str("1/2E5").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::from_integer(BigInt::from(50000)))
);

// Negative numbers in fractional notation
let ratio = IcuRatio::from_str("-1/2").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::new(BigInt::from(-1), BigInt::from(2)))
);

// Negative numbers in decimal notation
let ratio = IcuRatio::from_str("-1.5").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::new(BigInt::from(-3), BigInt::from(2)))
);

// Negative numbers in scientific notation
let ratio = IcuRatio::from_str("-1.5E6").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::from_integer(BigInt::from(-1500000)))
);

// Negative numbers in scientific notation with commas
let ratio = IcuRatio::from_str("-1,500E6").unwrap();
assert_eq!(
    ratio,
    IcuRatio::from(Ratio::from_integer(BigInt::from(-1500000000)))
);

// Corner cases

// Empty string
let ratio = IcuRatio::from_str("").unwrap();
assert_eq!(ratio, IcuRatio::zero());

// Single dot
let ratio = IcuRatio::from_str(".").unwrap();
assert_eq!(ratio, IcuRatio::zero());

// Single minus
let ratio = IcuRatio::from_str("-").unwrap();
assert_eq!(ratio, IcuRatio::zero());

// Single plus
let ratio = IcuRatio::from_str("+").unwrap();
assert_eq!(ratio, IcuRatio::zero());

// Only zeros after dot
let ratio = IcuRatio::from_str(".000").unwrap();
assert_eq!(ratio, IcuRatio::zero());

// Error cases
// Division by zero
assert!(IcuRatio::from_str("1/0").is_err());

// Multiple slashes
assert!(IcuRatio::from_str("1/2/3").is_err());

// Non-numeric characters in fractions
assert!(IcuRatio::from_str("1/2A").is_err());

// Multiple scientific notations
assert!(IcuRatio::from_str("1.5E6E6").is_err());

// Multiple decimal points
assert!(IcuRatio::from_str("1.5.6").is_err());

// Exponent part is not an integer
assert!(IcuRatio::from_str("1.5E6.5").is_err());

NOTE: You can add as many commas as you want in the string, they will be disregarded.

source§

type Err = RatioFromStrError

The associated error which can be returned from parsing.
source§

impl Mul<&IcuRatio> for &IcuRatio

source§

type Output = IcuRatio

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &IcuRatio) -> IcuRatio

Performs the * operation. Read more
source§

impl Mul for IcuRatio

source§

type Output = IcuRatio

The resulting type after applying the * operator.
source§

fn mul(self, rhs: IcuRatio) -> IcuRatio

Performs the * operation. Read more
source§

impl MulAssign<&SiPrefix> for IcuRatio

source§

fn mul_assign(&mut self, rhs: &SiPrefix)

Performs the *= operation. Read more
source§

impl MulAssign for IcuRatio

source§

fn mul_assign(&mut self, rhs: IcuRatio)

Performs the *= operation. Read more
source§

impl One for IcuRatio

source§

fn one() -> IcuRatio

Returns the multiplicative identity element of Self, 1. Read more
source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
source§

impl Ord for IcuRatio

source§

fn cmp(&self, other: &IcuRatio) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for IcuRatio

source§

fn eq(&self, other: &IcuRatio) -> 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 PartialOrd for IcuRatio

source§

fn partial_cmp(&self, other: &IcuRatio) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Pow<i32> for IcuRatio

source§

type Output = IcuRatio

The result after applying the operator.
source§

fn pow(self, exp: i32) -> IcuRatio

Returns self to the power rhs. Read more
source§

impl Sub for IcuRatio

source§

type Output = IcuRatio

The resulting type after applying the - operator.
source§

fn sub(self, rhs: IcuRatio) -> IcuRatio

Performs the - operation. Read more
source§

impl SubAssign for IcuRatio

source§

fn sub_assign(&mut self, rhs: IcuRatio)

Performs the -= operation. Read more
source§

impl Zero for IcuRatio

source§

fn zero() -> IcuRatio

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

impl Eq for IcuRatio

source§

impl StructuralPartialEq for IcuRatio

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 T)

🔬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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T
where T: Send + Sync,