pub struct Positive(pub Decimal);Expand description
A wrapper type that represents a guaranteed positive decimal value.
This type encapsulates a Decimal value and ensures through its API that
the contained value is always positive (greater than or equal to zero).
Tuple Fields§
§0: DecimalImplementations§
Source§impl Positive
impl Positive
Sourcepub const INFINITY: Positive
pub const INFINITY: Positive
Represents the maximum positive value possible (effectively infinity).
Sourcepub fn new(value: f64) -> Result<Self, PositiveError>
pub fn new(value: f64) -> Result<Self, PositiveError>
Creates a new Positive value from a 64-bit floating-point number.
Sourcepub fn new_decimal(value: Decimal) -> Result<Self, PositiveError>
pub fn new_decimal(value: Decimal) -> Result<Self, PositiveError>
Creates a new Positive value directly from a Decimal.
Sourcepub fn to_dec_ref(&self) -> &Decimal
pub fn to_dec_ref(&self) -> &Decimal
Returns the inner Decimal ref.
Sourcepub fn to_f64_checked(&self) -> Option<f64>
pub fn to_f64_checked(&self) -> Option<f64>
Converts the value to f64, returning None if conversion fails.
Sourcepub fn to_f64_lossy(&self) -> f64
pub fn to_f64_lossy(&self) -> f64
Converts the value to f64 with lossy conversion (returns 0.0 on failure).
Sourcepub fn to_i64_checked(&self) -> Option<i64>
pub fn to_i64_checked(&self) -> Option<i64>
Converts the value to i64, returning None if conversion fails.
Sourcepub fn to_u64_checked(&self) -> Option<u64>
pub fn to_u64_checked(&self) -> Option<u64>
Converts the value to u64, returning None if conversion fails.
Sourcepub fn to_usize_checked(&self) -> Option<usize>
pub fn to_usize_checked(&self) -> Option<usize>
Converts the value to usize, returning None if conversion fails.
Sourcepub fn pow(&self, n: Positive) -> Positive
pub fn pow(&self, n: Positive) -> Positive
Computes the result of raising the current value to the power of the given exponent.
Sourcepub fn powu(&self, n: u64) -> Positive
pub fn powu(&self, n: u64) -> Positive
Raises the current value to the power of n using unsigned integer exponentiation.
Sourcepub fn round_to_nice_number(&self) -> Positive
pub fn round_to_nice_number(&self) -> Positive
Rounds the current value to a “nice” number, based on its magnitude.
Sourcepub fn sqrt_checked(&self) -> Result<Positive, PositiveError>
pub fn sqrt_checked(&self) -> Result<Positive, PositiveError>
Calculates the square root, returning an error if it fails.
Sourcepub fn round_to(&self, decimal_places: u32) -> Positive
pub fn round_to(&self, decimal_places: u32) -> Positive
Rounds the value to a specified number of decimal places.
Sourcepub fn format_fixed_places(&self, decimal_places: u32) -> String
pub fn format_fixed_places(&self, decimal_places: u32) -> String
Formats the value with a fixed number of decimal places.
Sourcepub fn clamp(&self, min: Positive, max: Positive) -> Positive
pub fn clamp(&self, min: Positive, max: Positive) -> Positive
Clamps the value between a minimum and maximum.
Sourcepub fn ceiling(&self) -> Positive
pub fn ceiling(&self) -> Positive
Returns the smallest integer greater than or equal to the value.
Sourcepub fn sub_or_zero(&self, other: &Decimal) -> Positive
pub fn sub_or_zero(&self, other: &Decimal) -> Positive
Subtracts a decimal value, returning zero if the result would be negative.
Sourcepub fn sub_or_none(&self, other: &Decimal) -> Option<Positive>
pub fn sub_or_none(&self, other: &Decimal) -> Option<Positive>
Subtracts a decimal value, returning None if the result would be negative.
Sourcepub fn checked_sub(&self, rhs: &Self) -> Result<Self, PositiveError>
pub fn checked_sub(&self, rhs: &Self) -> Result<Self, PositiveError>
Checked subtraction that returns Result instead of panicking.
Sourcepub fn saturating_sub(&self, rhs: &Self) -> Self
pub fn saturating_sub(&self, rhs: &Self) -> Self
Saturating subtraction that returns ZERO instead of negative.
Sourcepub fn checked_div(&self, rhs: &Self) -> Result<Self, PositiveError>
pub fn checked_div(&self, rhs: &Self) -> Result<Self, PositiveError>
Checked division that returns Result instead of panicking.
Sourcepub fn is_multiple(&self, other: f64) -> bool
pub fn is_multiple(&self, other: f64) -> bool
Checks whether the value is a multiple of another f64 value.
Sourcepub fn is_multiple_of(&self, other: &Positive) -> bool
pub fn is_multiple_of(&self, other: &Positive) -> bool
Checks whether the value is a multiple of another Positive value.
Trait Implementations§
Source§impl AbsDiffEq for Positive
impl AbsDiffEq for Positive
Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq.Source§impl AddAssign<&Positive> for Decimal
impl AddAssign<&Positive> for Decimal
Source§fn add_assign(&mut self, rhs: &Positive)
fn add_assign(&mut self, rhs: &Positive)
+= operation. Read moreSource§impl AddAssign<Decimal> for Positive
impl AddAssign<Decimal> for Positive
Source§fn add_assign(&mut self, rhs: Decimal)
fn add_assign(&mut self, rhs: Decimal)
+= operation. Read moreSource§impl AddAssign<Positive> for Decimal
impl AddAssign<Positive> for Decimal
Source§fn add_assign(&mut self, rhs: Positive)
fn add_assign(&mut self, rhs: Positive)
+= operation. Read moreSource§impl AddAssign for Positive
impl AddAssign for Positive
Source§fn add_assign(&mut self, other: Positive)
fn add_assign(&mut self, other: Positive)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Positive
impl<'de> Deserialize<'de> for Positive
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl MulAssign<&Positive> for Decimal
impl MulAssign<&Positive> for Decimal
Source§fn mul_assign(&mut self, rhs: &Positive)
fn mul_assign(&mut self, rhs: &Positive)
*= operation. Read moreSource§impl MulAssign<Decimal> for Positive
impl MulAssign<Decimal> for Positive
Source§fn mul_assign(&mut self, rhs: Decimal)
fn mul_assign(&mut self, rhs: Decimal)
*= operation. Read moreSource§impl MulAssign<Positive> for Decimal
impl MulAssign<Positive> for Decimal
Source§fn mul_assign(&mut self, rhs: Positive)
fn mul_assign(&mut self, rhs: Positive)
*= operation. Read moreSource§impl Ord for Positive
impl Ord for Positive
Source§impl PartialOrd<&Positive> for f64
impl PartialOrd<&Positive> for f64
Source§impl PartialOrd<Decimal> for Positive
impl PartialOrd<Decimal> for Positive
Source§impl PartialOrd<Positive> for f64
impl PartialOrd<Positive> for f64
Source§impl PartialOrd<f64> for &Positive
impl PartialOrd<f64> for &Positive
Source§impl PartialOrd<f64> for Positive
impl PartialOrd<f64> for Positive
Source§impl PartialOrd for Positive
impl PartialOrd for Positive
Source§impl RelativeEq for Positive
impl RelativeEq for Positive
Source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
Source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
Source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq.