1pub trait YayNay {
2 fn yay(&self) -> bool;
3 fn nay(&self) -> bool;
4}
5impl YayNay for bool {
6 fn yay(&self) -> bool {*self}
7 fn nay(&self) -> bool {!*self}
8}
9impl <A> YayNay for Option<A>{
10 fn yay(&self) -> bool {self.is_some()}
11 fn nay(&self) -> bool {self.is_none()}
12}
13impl <A,B> YayNay for Result<A,B>{
14 fn yay(&self) -> bool {self.is_ok()}
15 fn nay(&self) -> bool {self.is_err()}
16}
17
18#[macro_export]
19macro_rules! flow_base {
20 ($block:block $($any:tt)*) => {if $($any)* {$block}};
21}
22
23#[macro_export]
24macro_rules! flow_base_let {
25 ($block:block ?$opt:expr) => {
26 if $opt.nay() {$block}
27 };
28 ($block:block *$($opt:tt)*) => {
29 let $($opt)* else {$block};
30 };
31 ($block:block $($var:ident)* =$opt:expr $(,$($plus:tt)*)*) => {
32 let $($var)* = {
33 let _tmp = $opt;
34 if _tmp.nay() {$block}
35 _tmp.unwrap()$(.$($plus)*)*
36 };
37 };
38 ($block:block ($($($var:ident)*),*)=$opt:expr $(,$($plus:tt)*)*) => {
39 let ($($($var)*),*) = {
40 let _tmp = $opt;
41 if _tmp.nay() {$block}
42 _tmp.unwrap()$(.$($plus)*)*
43 };
44 };
45 ($block:block [$($($var:ident)*),*]=$opt:expr $(,$($plus:tt)*)*) => {
46 let [$($($var)*),*] = {
47 let _tmp = $opt;
48 if _tmp.nay() {$block}
49 _tmp.unwrap()$(.$($plus)*)*
50 };
51 };
52}
53
54#[macro_export]
55macro_rules! exit {
56 () => {return Default::default()};
57 (>if ($($any:tt)*) $($ret:tt)*) => {flow_base!{{return $($ret)*} $($any)*}};
58 (if $($any:tt)*) => {flow_base!{{return Default::default()} $($any)*}};
59 (>($($any:tt)*) $($ret:tt)*) => {flow_base_let!{{return $($ret)*} $($any)*}};
60 ($($any:tt)*) => {flow_base_let!{{return Default::default()} $($any)*}};
61}
62
63#[macro_export]
64macro_rules! next {
65 (if $($any:tt)*) => {flow_base!{{continue} $($any)*}};
66 ($($any:tt)*) => {flow_base_let!{{continue} $($any)*}};
67}
68
69#[macro_export]
70macro_rules! kill {
71 (if $($any:tt)*) => {flow_base!{{panic!()} $($any)*}};
72 ($($any:tt)*) => {flow_base_let!{{panic!()} $($any)*}};
73}
74
75#[macro_export]
76macro_rules! hold {
77 (if $($any:tt)*) => {flow_base!{{break} $($any)*}};
78 ($($any:tt)*) => {flow_base_let!{{break} $($any)*}};
79}