wyz/
exit.rs

1/*! `exit!` macro
2
3The `exit!` macro simplifies exiting with an error code, and optionally printing
4an error message prior to exit.
5
6# Examples
7
8This example exits with status `1`.
9
10```rust,should_panic
11wyz::exit!();
12```
13
14This example exits with status `2`.
15
16```rust,should_panic
17wyz::exit!(2);
18```
19
20This example exits with status `3`, and uses `eprintln!` to print an error
21message before exiting. Note that if `stderr` has been closed, this will crash
22the program with a panic due to `SIGPIPE`, and *not* call `process::exit()`.
23
24```rust,should_panic
25wyz::exit!(3, "Error status: {}", "testing");
26```
27!*/
28
29#![cfg(feature = "std")]
30
31/// `exit!` macro
32#[macro_export]
33macro_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}