#unreachable #bug #less #panic #aranya #replace #unwrap

no-std aranya-buggy

A less panicky replacement for unreachable!() and unwrap

1 unstable release

0.1.0 Oct 16, 2024

#1054 in Rust patterns

Download history 116/week @ 2024-10-17 39/week @ 2024-10-24 61/week @ 2024-10-31 39/week @ 2024-11-07 90/week @ 2024-11-14 139/week @ 2024-11-21 85/week @ 2024-11-28 255/week @ 2024-12-05 111/week @ 2024-12-12 78/week @ 2024-12-19 37/week @ 2024-12-26 518/week @ 2025-01-02 282/week @ 2025-01-09 272/week @ 2025-01-16 530/week @ 2025-01-23 387/week @ 2025-01-30

1,700 downloads per month
Used in 24 crates (12 directly)

AGPL-3.0-only

8KB
135 lines

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

Dependencies

~4KB