https://github.com/antonio-hickey/or-panic
https://github.com/antonio-hickey/or-panic
dx extension option panic result rust
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/antonio-hickey/or-panic
- Owner: antonio-hickey
- License: apache-2.0
- Created: 2025-11-18T06:05:55.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2025-11-18T06:47:07.000Z (7 months ago)
- Last Synced: 2025-11-18T08:22:56.852Z (7 months ago)
- Topics: dx, extension, option, panic, result, rust
- Language: Rust
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
or-panic 🫨🤯
===
A tiny extension trait that adds idiomatic `.or_panic(..)` methods to `Option` and `Result`.
```toml
[dependencies]
or-panic = "1.0.0"
```
## Example
```rust
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`:
```toml
[dependencies]
or-panic = "1.0.0"
```
Import the traits:
```rust
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:
```toml
[dependencies]
or-panic = { version = "1.0.0", default-features = false, features = ["no_std"] }
```
#### License
Licensed under either of Apache License, Version
2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.