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 #![cfg(feature = "std")] 29 30 /// `exit!` macro 31 #[macro_export] 32 macro_rules! exit { 33 () => { 34 $crate::exit!(1); 35 }; 36 37 ( $num:expr $(,)? ) => { 38 ::std::process::exit($num); 39 }; 40 41 ( $num:expr, $fmt:expr $( , $arg:expr )* $(,)? ) => {{ 42 eprintln!($fmt $( , $arg )*); 43 $crate::exit!($num); 44 }}; 45 } 46