ExitErrorResult

Trait ExitErrorResult 

Source
pub trait ExitErrorResult<T> {
    // Required methods
    fn unwrap_or_eprint_exit(self) -> T;
    unsafe fn unwrap_or_eprint_signal_safe_exit(self) -> T;
    fn ok_or_eprint(self) -> Option<T>;
    fn ok_or_eprint_signal_safe(self) -> Option<T>;
}
Expand description

This trait defines a Result with our own ExitError. This allows exiting the program with the error code specified by the ExitError, as well as consuming itself and returning an Option after printing the Error to stderr.

Note: Normally, you should handle the error in the main function as in the provided example (see How? in crate documentation), but these functions can be useful at times when that might not be practical (for example, the child process failing an execve after a successful fork.

Required Methods§

Source

fn unwrap_or_eprint_exit(self) -> T

Similar to Result::unwrap, but prints the error (if present) to stderr and exits with the specified exit code instead of causing the program to panic.

Note: Normally, you should handle the error in the main function as in the provided example (see How? in crate documentation).

§Safety

The caller must ensure that stderr (fd 2) is open.

Source

unsafe fn unwrap_or_eprint_signal_safe_exit(self) -> T

Same as ExitErrorResult::unwrap_or_eprint_exit, but attempts to write() directly to stderr and not to call any non-signal-safe functions. Useful when one is the child in a multi-threaded program after a call to fork().

§Safety

The caller must ensure that stderr (fd 2) is open.

_exit is safe to call from the fork()-ed child as it’s signal-safe. However, it doesn’t call destructors (as opposed to exiting from main) nor does it call any exit functions if they are set, so caller should only call this from a fork()-ed child.

Source

fn ok_or_eprint(self) -> Option<T>

Consumes the result, prints the error (if present) to stderr, and returns an Option of the underlying value.

§Safety

The caller must ensure that stderr (fd 2) is open.

Source

fn ok_or_eprint_signal_safe(self) -> Option<T>

Same as ExitErrorResult::ok_or_eprint, but attempts to write() directly to stderr and not to call any non-signal-safe functions. Useful when one is the child in a multi-threaded program after a call to fork().

§Safety

The caller must ensure that stderr (fd 2) is open.

Implementations on Foreign Types§

Source§

impl<T, S: AsRef<str>> ExitErrorResult<T> for Result<T, ExitError<S>>

Implementors§