Macro uucore::show_if_err
source · [−]macro_rules! show_if_err {
($res:expr) => { ... };
}
Expand description
Display an error and set global exit code in error case.
Wraps around show!
and takes a crate::error::UResult
instead of a
crate::error::UError
type. This macro invokes show!
if the
crate::error::UResult
is an Err
-variant. This can be invoked directly
on the result of a function call, like in the install
utility:
ⓘ
show_if_err!(copy(sourcepath, &targetpath, b));
Examples
ⓘ
let is_ok = Ok(1);
// This does nothing at all
show_if_err!(is_ok);
let is_err = Err(USimpleError::new(1, "I'm an error").into());
// Calls `show!` on the contained USimpleError
show_if_err!(is_err);