buggy 0.1.0

A less panicky replacement for unreachable!() and unwrap
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented2 out of 6 items with examples
  • Size
  • Source code size: 8.82 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.02 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • aranya-project/spideroak-core
    1 0 5
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • aranya-project-bot

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(())
}