Merge pull request #695 from matthiasbeyer/libimagutil/warn-exit
libimagutil: Add warn_exit() convenience helper
This commit is contained in:
commit
7bf654158e
2 changed files with 23 additions and 0 deletions
|
@ -24,4 +24,5 @@ pub mod ismatch;
|
||||||
pub mod iter;
|
pub mod iter;
|
||||||
pub mod key_value_split;
|
pub mod key_value_split;
|
||||||
pub mod variants;
|
pub mod variants;
|
||||||
|
pub mod warn_exit;
|
||||||
pub mod warn_result;
|
pub mod warn_result;
|
||||||
|
|
22
libimagutil/src/warn_exit.rs
Normal file
22
libimagutil/src/warn_exit.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/// This function prints the string `s` via the `warn!()` macro and then exits with the code `code`
|
||||||
|
/// as status.
|
||||||
|
///
|
||||||
|
/// Convenience function to be used in matches to remove one scope:
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// use libimagutil::warn_exit::warn_exit;
|
||||||
|
///
|
||||||
|
/// let r: Result<i32, i32> = Err(1);
|
||||||
|
/// match r {
|
||||||
|
/// Err(e) => warn_exit("Warning!", 42),
|
||||||
|
/// Ok(num) => { /* ... */ }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
pub fn warn_exit(s: &str, code: i32) -> ! {
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
|
warn!("{}", s);
|
||||||
|
exit(code);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue