pub enum SafeMathError {
Overflow,
DivisionByZero,
InfiniteOrNaN,
}Expand description
Error types returned by safe arithmetic operations.
This enum represents all possible error conditions that can occur during arithmetic operations.
§Examples
use safe_math::SafeMathError;
// Example of handling different error types
fn handle_result(result: Result<u8, SafeMathError>) {
match result {
Ok(value) => println!("Result: {}", value),
Err(SafeMathError::Overflow) => println!("Overflow occurred"),
Err(SafeMathError::DivisionByZero) => println!("Division by zero"),
Err(SafeMathError::InfiniteOrNaN) => println!("Infinite or NaN result"),
#[cfg(feature = "derive")]
Err(SafeMathError::NotImplemented) => println!("Operation not implemented"),
}
}§Features
The NotImplemented variant is only available when the derive feature is enabled.
Variants§
Overflow
Arithmetic overflow or underflow occurred.
DivisionByZero
Division or remainder operation by zero.
InfiniteOrNaN
Operation resulted in infinite or NaN value (floating-point types).
Trait Implementations§
Source§impl Clone for SafeMathError
impl Clone for SafeMathError
Source§fn clone(&self) -> SafeMathError
fn clone(&self) -> SafeMathError
Returns a duplicate 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 SafeMathError
impl Debug for SafeMathError
Source§impl Display for SafeMathError
impl Display for SafeMathError
Source§impl Error for SafeMathError
impl Error for SafeMathError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<SafeMathError> for ()
impl From<SafeMathError> for ()
Source§fn from(_: SafeMathError) -> Self
fn from(_: SafeMathError) -> Self
Converts to this type from the input type.
Source§impl PartialEq for SafeMathError
impl PartialEq for SafeMathError
impl Copy for SafeMathError
impl Eq for SafeMathError
impl StructuralPartialEq for SafeMathError
Auto Trait Implementations§
impl Freeze for SafeMathError
impl RefUnwindSafe for SafeMathError
impl Send for SafeMathError
impl Sync for SafeMathError
impl Unpin for SafeMathError
impl UnwindSafe for SafeMathError
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