I do check function results on assignment using match statement. In some cases I want to exit the program with an error message like panic!() does. But how can I create a function or macro that can be used everywhere?
Example:
let args = match args::Args::parse() {
Ok(args) => args,
Err(e) => someerror("bla")
};
let mut statedoc = match state_loader.load() {
Ok(states) => states,
Err(e) => someerror("blub")
};
What does someerror() need to return to work everywhere?
someerrordoesn't need to return anything, but its implementation can panic or print an error and exit the process. In other words, you can callpanic!(s)insidesomeerroror, if you don't want your program to panic, you can calleprintln!("{}", s); std::process::exit(1);.