fyrox_core/
early.rs

1// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in all
11// copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21#[macro_export]
22macro_rules! some_or_return {
23    ($expr:expr) => {{
24        if let Some(v) = $expr {
25            v
26        } else {
27            return;
28        }
29    }};
30    ($expr:expr, $default:expr) => {{
31        if let Some(v) = $expr {
32            v
33        } else {
34            return $default;
35        }
36    }};
37}
38
39#[macro_export]
40macro_rules! ok_or_return {
41    ($expr:expr) => {{
42        if let Ok(v) = $expr {
43            v
44        } else {
45            return;
46        }
47    }};
48    ($expr:expr, $default:expr) => {{
49        if let Ok(v) = $expr {
50            v
51        } else {
52            return $default;
53        }
54    }};
55}
56
57#[macro_export]
58macro_rules! some_or_continue {
59    ($expr:expr) => {{
60        if let Some(v) = $expr {
61            v
62        } else {
63            continue;
64        }
65    }};
66    ($expr:expr, $lifetime:lifetime) => {{
67        if let Some(v) = $expr {
68            v
69        } else {
70            continue $lifetime;
71        }
72    }};
73}
74
75#[macro_export]
76macro_rules! ok_or_continue {
77    ($expr:expr) => {{
78        if let Ok(v) = $expr {
79            v
80        } else {
81            continue;
82        }
83    }};
84    ($expr:expr, $lifetime:lifetime) => {{
85        if let Ok(v) = $expr {
86            v
87        } else {
88            continue $lifetime;
89        }
90    }};
91}
92
93#[macro_export]
94macro_rules! some_or_break {
95    ($expr:expr) => {{
96        if let Some(v) = $expr {
97            v
98        } else {
99            break;
100        }
101    }};
102    ($expr:expr, $lifetime:lifetime) => {{
103        if let Some(v) = $expr {
104            v
105        } else {
106            break $lifetime;
107        }
108    }};
109}
110
111#[macro_export]
112macro_rules! ok_or_break {
113    ($expr:expr) => {{
114        if let Ok(v) = $expr {
115            v
116        } else {
117            break;
118        }
119    }};
120    ($expr:expr, $lifetime:lifetime) => {{
121        if let Ok(v) = $expr {
122            v
123        } else {
124            break $lifetime;
125        }
126    }};
127}