Unwrap Macros to help Clean up code and improve production. This does include a pub use of https://github.com/Mrp1Dev/loop_unwrap to gain access to unwrap loop macros.
/// Works like .unwrap
, if it's an Err(_) or None it calls return.
/// Will return No data or Data. Can use a Simple Closure
/// but if you want a closure with return type set you must make it like || -> i32 {1}()
``` fn rettestfail() -> i32 { let opt = None;
let _ = unwrap_or_return!(opt, 0);
1
}
fn retasoption_fail() -> Option
let _ = unwrap_or_return!(opt, Some(0));
None
} ``` fn test_send(x: i32) -> i32 { x + 1 }
fn retfnfail() -> i32 { let x = 5; let opt = None;
let _ = unwrap_or_return!(opt, test_send(x));
1
}
fn retclosurefail() -> i32 {
let x = 5;
let opt = None;
let _ = unwrap_or_return!(opt, || x + 1);
1
}
fn retclosureret_fail() -> i32 {
let x = 5;
let opt = None;
let _ = unwrap_or_return!(opt, || -> i32 { x + 1 }());
1
}
fn testnoreturn() {
let input = Option::None;
let parsedinput = unwrapor_return!(input);
}
```