Convenience macros for those uncertain times.
Whether you use this project, have learned something from it, or just like it, please consider supporting it by buying me a coffee, so I can dedicate more time on open-source projects like this :)
The crate exports one macro, maybe!. It runs a block when an Option holds a value, binding the unwrapped value to the given name:
use mayhaps::maybe;
let opt = Some(5);
maybe!(val from (opt) exists {
println!("got {}", val); // runs only when opt is Some
});An else variant runs a second block when the Option is empty:
use mayhaps::maybe;
let opt: Option<i32> = None;
maybe!(val from (opt) exists {
println!("got {}", val);
} else {
println!("nothing there"); // runs when opt is None
});You can check out the full license here
This project is licensed under the terms of the MPL-2.0 license.
