warrant 0.1.0

A Swift-guard-like macro for Rust
Documentation
  • Coverage
  • 66.67%
    2 out of 3 items documented0 out of 0 items with examples
  • Size
  • Source code size: 4.10 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 134.28 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • Documentation
  • ifsheldon/warrant
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ifsheldon

warrant

A guard macro that is like guard in Swift. It helps to better express code logic without mind twists when checking conditions.

It implements what I termed "procedural warranty".

Usages

Add warrant = "0.1.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::warrant is also aliased as warrant::guard if you come from Swift and prefer guard.

License

MIT

Additional References

  • Pattern Matched Guard: consider just use if-let-else
  • "Structural Warranty": to enforce a condition on a struct, nutype is a good one.