https://github.com/dekirisu/maflow
rust 'unwrap' macros, but it returns, continues or breaks
https://github.com/dekirisu/maflow
flow-control macros rust-lang
Last synced: over 1 year ago
JSON representation
rust 'unwrap' macros, but it returns, continues or breaks
- Host: GitHub
- URL: https://github.com/dekirisu/maflow
- Owner: dekirisu
- License: apache-2.0
- Created: 2024-07-01T16:42:03.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-09T13:49:38.000Z (about 2 years ago)
- Last Synced: 2025-03-28T00:51:10.500Z (over 1 year ago)
- Topics: flow-control, macros, rust-lang
- Language: Rust
- Homepage:
- Size: 8.79 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
maflow
Simple **Ma**cros, changing the **flow** of development:
- **`kill!( flow )`** panics
- **`exit!( flow )`** returns `::default()`
- **`next!( flow )`** continues
- **`hold!( flow )`** breaks
**Flow** can be:
1. **Option** `..!{ inner = option }` same as `let Some(inner) = option else {..}`
- `..!{ ?option }` same as `if option.is_none() {..}`
2. **Result** `..!{ inner = result }` same as `let Ok(inner) = result else {..}`
- `..!{ ?result }` same as `if result.is_err() {..}`
4. **bool** `..!{ if bool }` same as `if bool {..}`
5. **custom** `..!{ *Some(inner) = option }` same as `let Some(inner) = option else {..}`
## Example
```toml
[dependencies]
maflow = "0.1"
```
```rust
use maflow::*;
fn main(){
// Options and Results
let some = Some(true);
kill!{is_true = some} // same as .unwrap()
exit!{is_true = some} // returns default() if None => ()
for i in 0..9 {
next!{is_true = some} // continues if None
hold!{is_true = some} // breaks if None
if is_true {}
}
// Conditional
let is_true = true;
kill!{if is_true} // panics if ..
exit!{if is_true} // returns default() if ..
for i in 0..9 {
next!{if is_true} // continues if ..
hold!{if is_true} // breaks if ..
}
}
```
## Also..
..implements the trait `YayNay` for `Result`, `Option` and `bool` with those methods:
- `.yay()` returns `true` if `Ok(..)` `Some(..)` or `true`
- `.nay()` returns `true` for the negative counter part
---
### License
Licensed under either of Apache License, Version
2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.