or-panic 1.0.2

unwrap or panic
Documentation
  • Coverage
  • 37.5%
    3 out of 8 items documented1 out of 5 items with examples
  • Size
  • Source code size: 20.61 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.24 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 21s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • antonio-hickey/or-panic
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • antonio-hickey

or-panic 🫨🤯

A tiny extension trait that adds idiomatic .or_panic(..) methods to Option and Result.

[dependencies]
or-panic = "1.0.0"

Example

use or_panic::ResultOrPanic;

fn main() {
    let duration = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .or_panic("oh no, the chrono demons have reversed the fabric of time");

    let secs = duration.as_secs();
    println!("Seconds since epoch: {secs}");
}

Features

  • Ergonomic unwrapping
  • Works with any Display
  • Pretty panic messages with Result
  • Context on the exact line of panic
  • Optional no_std support
    • enabled via:
      default-features = false
      features = ["no_std"]   
      

Quick Start

Add the crate to your Cargo.toml:

[dependencies]
or-panic = "1.0.0"

Import the traits:

use or_panic::prelude::*;

Use it:

let host = std::env::var("HOST")
    .or_panic("HOST environment variable must be set");

no_std support

or-panic supports no_std environments.

Enable no_std mode like so:

[dependencies]
or-panic = { version = "1.0.0", default-features = false, features = ["no_std"] }

License