embassy_stm32_plus/macro/option.rs
1/// match Option <br />
2/// if is Some, will be return value <br />
3/// if is Nome, will be return custom value and exit method
4#[macro_export]
5macro_rules! match_some_return {
6 ($opt:expr) => {
7 $crate::match_some_return!($opt,())
8 };
9 ($opt:expr,$r:expr) => {
10 $crate::match_some_exec!($opt,{return $r})
11 };
12}
13
14/// match Option <br />
15/// if is Some, will be return value and keep loop <br />
16/// if is Nome, will be continue the loop
17#[macro_export]
18macro_rules! match_some_continue {
19 ($opt:expr) => {
20 $crate::match_some_exec!($opt,continue);
21 };
22}
23
24/// match Option <br />
25/// if is Some, will be return value and keep loop <br />
26/// if is Nome, will be return custom value and break loop<br />
27/// need to be used in loop to break value, invalid in for and while
28#[macro_export]
29macro_rules! match_some_break {
30 ($opt:expr) => {
31 $crate::match_some_break!($opt,())
32 };
33 ($opt:expr,$r:expr) => {
34 $crate::match_some_exec!($opt,{break $r})
35 };
36}
37
38/// match Option <br />
39/// if is Some, will be return value <br />
40/// if is Nome, will be return custom value
41#[macro_export]
42macro_rules! match_some_exec {
43 ($opt:expr,$exec:expr) => {
44 match $opt {
45 Some(s) => s,
46 None => $exec
47 }
48 };
49}