[−][src]Function idioma::exit_if_error
pub fn exit_if_error<O>(result: Result<O, Error>) -> Result<O, Error>
Somethimes you get a Result
and you want to continue execution as normal if case it's Ok
or
exit if it's Err
. This function allows you to do precisely that.
It gives you back the Result
, but you will only ever be able to actually touch it if you
passed in an Ok
because exit_if_error
will simply terminate on Err
. Therefore, you can do
something like this:
use idioma::*; let message = exit_if_error(Ok("hello world")).unwrap(); println!(message);
In this case, the call to unwrap
is totally safe. In some cases, compiler
will shout at you for doing that, so just give it #[allow(unused)]
.