Debian Codegraph @

debian/rust-vendor/wyz/src/exit.rs

raw
1 /*! `exit!` macro
2
3 The `exit!` macro simplifies exiting with an error code, and optionally printing
4 an error message prior to exit.
5
6 # Examples
7
8 This example exits with status `1`.
9
10 ```rust,should_panic
11 wyz::exit!();
12 ```
13
14 This example exits with status `2`.
15
16 ```rust,should_panic
17 wyz::exit!(2);
18 ```
19
20 This example exits with status `3`, and uses `eprintln!` to print an error
21 message before exiting. Note that if `stderr` has been closed, this will crash
22 the program with a panic due to `SIGPIPE`, and *not* call `process::exit()`.
23
24 ```rust,should_panic
25 wyz::exit!(3, "Error status: {}", "testing");
26 ```
27 !*/
28
29 #![cfg(feature = "std")]
30
31 /// `exit!` macro
32 #[macro_export]
33 macro_rules! exit {
34 () => {
35 $crate::exit!(1);
36 };
37
38 ( $num:expr $(,)? ) => {
39 ::std::process::exit($num);
40 };
41
42 ( $num:expr, $fmt:expr $( , $arg:expr )* $(,)? ) => {{
43 eprintln!($fmt $( , $arg )*);
44 $crate::exit!($num);
45 }};
46 }