suwrap
Explicit, contextual replacement for
unwrap().
suwrap is a tiny utility crate that provides a disciplined alternative to
unwrap() and expect().
It makes invariant failures explicit and consistently contextual.
✨ Why?
unwrap() and expect() panic without structured meaning.
They:
- Hide the invariant being enforced
- Lose domain context
- Create inconsistent panic messages
- Encourage casual failure handling
suwrap enforces explicit invariant naming and consistent failure style.
📦 Installation
Add to your Cargo.toml:
[]
= "0.1"
🔥 Basic Usage
Instead of this:
let user = maybe_user.unwrap;
Write this:
use Suwrap;
let user = maybe_user.sunwrap;
If the invariant fails, it panics with a structured message:
[INVARIANT VIOLATION]
Context: user must exist
🧠 Option Example
use Suwrap;
let config = var
.ok
.sunwrap;
🧠 Result Example
use Suwrap;
let file = read_to_string
.sunwrap;
🎯 Design Principles
- No silent unwrap
- Explicit invariant description
- Zero runtime cost beyond panic formatting
- Minimal API surface
- No dependencies
🛡 Philosophy
sunwrap() is not error handling.
It is invariant enforcement.
Use it when:
- Failure means programmer bug
- The program should stop
- The condition must always hold
Do not use it for recoverable errors.
📄 License
MIT OR Apache-2.0