Registry / utility / guard
library0.5.2rscratesunverified

Macro implementation of RFC 1303: a guard-let-else statement similar to Swift's guard let, enabling early returns on pattern match failures.

# Cargo.toml [dependencies] guard = "0.5.2"
INSTALL
IMPORT
SIG · GUARD
G
guard
utilityrustv0.5.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

guard
use guard::guard;

Uses the guard macro to unwrap an Option with an early return.

use guard::guard; fn process(value: Option<i32>) -> i32 { guard!(let Some(x) = value else { return 0 }); x * 2 } fn main() { println!("{}", process(Some(5))); }
Debug
Known issues
gotchaThe guard macro is a nightly-only feature and requires Rust nightly to compile.
fix
Switch to Rust nightly via `rustup default nightly` or use a stable alternative like `if let`.
affects: >=0.5.0
Upgrade
Version history
0.5.2latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
guard — cargo add guard · libregistry