Skip to main content

PositiveError

Enum PositiveError 

Source
pub enum PositiveError {
    InvalidValue {
        value: f64,
        reason: String,
    },
    ArithmeticError {
        operation: String,
        reason: String,
    },
    ConversionError {
        from_type: String,
        to_type: String,
        reason: String,
    },
    OutOfBounds {
        value: f64,
        min: f64,
        max: f64,
    },
    InvalidPrecision {
        precision: i32,
        reason: String,
    },
    Other(String),
}
Expand description

Represents errors that can occur during positive decimal operations.

This enum provides a structured way to handle various error conditions that may arise when working with positive decimal values, including validation, arithmetic operations, conversions, and precision issues.

§Variants

  • InvalidValue - Value cannot be represented as a valid positive decimal
  • ArithmeticError - Error during mathematical operations
  • ConversionError - Error when converting between types
  • OutOfBounds - Value exceeds defined limits
  • InvalidPrecision - Invalid decimal precision settings
  • Other - Catch-all for other errors

Variants§

§

InvalidValue

Error when attempting to create a positive decimal from an invalid value.

Occurs when a value cannot be properly represented as a positive decimal, such as when it’s NaN, infinity, negative, or otherwise unsuitable.

Fields

§value: f64

The problematic value that caused the error.

§reason: String

Detailed explanation of why the value is invalid.

§

ArithmeticError

Error when performing decimal arithmetic operations.

Occurs during mathematical operations such as addition, subtraction, multiplication, or division when the operation cannot be completed correctly (e.g., division by zero, overflow, result would be negative).

Fields

§operation: String

The operation that failed (e.g., “subtraction”, “division”).

§reason: String

Detailed explanation of why the operation failed.

§

ConversionError

Error when converting between decimal types.

Occurs when a decimal value cannot be correctly converted from one representation to another, such as between different precision levels or between different decimal formats.

Fields

§from_type: String

The source type being converted from.

§to_type: String

The destination type being converted to.

§reason: String

Detailed explanation of why the conversion failed.

§

OutOfBounds

Error when a decimal value exceeds its bounds.

Occurs when a decimal value falls outside of acceptable minimum or maximum values for a specific calculation context.

Fields

§value: f64

The value that is out of bounds.

§min: f64

The minimum acceptable value.

§max: f64

The maximum acceptable value.

§

InvalidPrecision

Error when decimal precision is invalid.

Occurs when an operation specifies or results in an invalid precision level that cannot be properly handled.

Fields

§precision: i32

The problematic precision value.

§reason: String

Detailed explanation of why the precision is invalid.

§

Other(String)

Catch-all error for other positive decimal errors.

Implementations§

Source§

impl PositiveError

Source

pub fn invalid_value(value: f64, reason: &str) -> Self

Creates a new InvalidValue error.

§Arguments
  • value - The problematic floating-point value
  • reason - Explanation of why the value is invalid
§Returns

A new PositiveError::InvalidValue instance

Source

pub fn arithmetic_error(operation: &str, reason: &str) -> Self

Creates a new ArithmeticError error.

§Arguments
  • operation - The name of the operation that failed
  • reason - Explanation of why the operation failed
§Returns

A new PositiveError::ArithmeticError instance

Source

pub fn conversion_error(from_type: &str, to_type: &str, reason: &str) -> Self

Creates a new ConversionError error.

§Arguments
  • from_type - The source type being converted from
  • to_type - The destination type being converted to
  • reason - Explanation of why the conversion failed
§Returns

A new PositiveError::ConversionError instance

Source

pub fn out_of_bounds(value: f64, min: f64, max: f64) -> Self

Creates a new OutOfBounds error.

§Arguments
  • value - The out-of-bounds floating-point value
  • min - The lower bound (inclusive) of the valid range
  • max - The upper bound (inclusive) of the valid range
§Returns

A new PositiveError::OutOfBounds instance

Source

pub fn invalid_precision(precision: i32, reason: &str) -> Self

Creates a new InvalidPrecision error.

§Arguments
  • precision - The problematic precision value
  • reason - Explanation of why the precision is invalid
§Returns

A new PositiveError::InvalidPrecision instance

Trait Implementations§

Source§

impl Debug for PositiveError

Source§

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

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

impl Display for PositiveError

Source§

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

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

impl Error for PositiveError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&str> for PositiveError

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for PositiveError

Source§

fn from(s: String) -> Self

Converts to this type from the input type.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

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.