Enum overflow_error::CannotDiv [] [src]

pub enum CannotDiv {
    ByZero,
    WouldOverflow,
}

Division could not be performed; either [DivByZero] or [WouldOverflow].

Variants

[DivByZero]

[WouldOverflow]

Methods

impl CannotDiv
[src]

[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);

[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]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for CannotDiv
[src]

[src]

Formats the value using the given formatter. Read more

impl PartialEq for CannotDiv
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl Eq for CannotDiv
[src]

impl Hash for CannotDiv
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl From<DivByZero> for CannotDiv
[src]

[src]

Performs the conversion.

impl From<WouldOverflow> for CannotDiv
[src]

[src]

Performs the conversion.

impl Display for CannotDiv
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for CannotDiv

impl Sync for CannotDiv