Crate buggy

Crate buggy 

Source
Expand description

Error handling similar to core::unreachable, but less panicky.

§Configuration

Panicking is controlled by debug_assertions.

  • By default, in debug/test builds, we panic to make it easier to find bugs.
  • In release builds, we don’t want to panic so we instead return Result<T, Bug>.

§Usage

use buggy::{bug, Bug, BugExt};

#[derive(Debug)]
enum MyError {
    TooManyFrobs,
    Bug(Bug),
}

impl From<Bug> for MyError {
    fn from(err: Bug) -> Self {
        Self::Bug(err)
    }
}

fn main() -> Result<(), MyError> {
    let x: u32 = 42;

    let sum = x.checked_add(100).assume("x is small")?;

    if x % 2 != 0 {
        bug!("x is always even because I said so");
    }

    Ok(())
}

Macros§

bug
Like core::unreachable, but less panicky. See also crate docs.

Structs§

Bug
Error type for errors that should be unreachable, indicating a bug.

Traits§

BugExt
Extension trait for assuming an option or result can be unwrapped.