Enum overflow_error::CannotDiv
[−]
[src]
pub enum CannotDiv { ByZero, WouldOverflow, }
Division could not be performed; either [DivByZero
] or [WouldOverflow
].
Variants
ByZero
[DivByZero
]
WouldOverflow
[WouldOverflow
]
Methods
impl CannotDiv
[src]
pub fn val<T>(self, val: T) -> CannotDivValue<T>
[src]
Adds a payload to this error, representing the left-hand-side of the division.
Examples
use overflow_error::*; fn checked_div(a: u32, b: u32) -> Result<u32, CannotDivValue<u32>> { if b == 0 { Err(CannotDiv::ByZero.val(a)) } else { a.checked_div(b).ok_or(CannotDiv::WouldOverflow.val(a)) } } let result = checked_div(1, 0); assert!(*result.unwrap_err().as_inner() == 1);
pub fn as_str(&self) -> &'static str
[src]
String representing the error.
Examples
use overflow_error::*; assert!(CannotDiv::ByZero.as_str() == DivByZero.as_str()); assert!(CannotDiv::WouldOverflow.as_str() == WouldOverflow.as_str());
Trait Implementations
impl Copy for CannotDiv
[src]
impl Clone for CannotDiv
[src]
fn clone(&self) -> CannotDiv
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for CannotDiv
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl PartialEq for CannotDiv
[src]
fn eq(&self, __arg_0: &CannotDiv) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Eq for CannotDiv
[src]
impl Hash for CannotDiv
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl From<DivByZero> for CannotDiv
[src]
impl From<WouldOverflow> for CannotDiv
[src]
fn from(_: WouldOverflow) -> CannotDiv
[src]
Performs the conversion.