| Crates.io | warrant |
| lib.rs | warrant |
| version | 0.2.0 |
| created_at | 2024-06-07 07:33:15.419933+00 |
| updated_at | 2025-06-27 09:07:22.051474+00 |
| description | A Swift-guard-like macro for Rust |
| homepage | https://github.com/ifsheldon/warrant |
| repository | https://github.com/ifsheldon/warrant |
| max_upload_size | |
| id | 1264474 |
| size | 6,637 |
A macro like guard in Swift.
It helps to better express code logic without mind twists when checking conditions.
It implements what I termed "procedural warranty".
Add warrant = "0.2.0" to your Cargo.toml.
Before
// if some condition is not satisfied, early return.
let condition = is_satisfied();
if !condition {
return;
}
// proceed
After
use warrant::warrant;
let condition = is_satisfied();
warrant!(condition, else {
return;
});
// proceed
warrant 0.2 also supports let chains if you use Rust Edition 2024 and Rust >= 1.88.0.
warrant::warrant is also aliased as warrant::guard if you come from Swift and prefer guard.
if-let-else