Struct std::process::ExitCode

1.61.0 · source · []
pub struct ExitCode(_);
Expand description

This type represents the status code the current process can return to its parent under normal termination.

ExitCode is intended to be consumed only by the standard library (via Termination::report()), and intentionally does not provide accessors like PartialEq, Eq, or Hash. Instead the standard library provides the canonical SUCCESS and FAILURE exit codes as well as From<u8> for ExitCode for constructing other arbitrary exit codes.

Portability

Numeric values used in this type don’t have portable meanings, and different platforms may mask different amounts of them.

For the platform’s canonical successful and unsuccessful codes, see the SUCCESS and FAILURE associated items.

Differences from ExitStatus

ExitCode is intended for terminating the currently running process, via the Termination trait, in contrast to ExitStatus, which represents the termination of a child process. These APIs are separate due to platform compatibility differences and their expected usage; it is not generally possible to exactly reproduce an ExitStatus from a child for the current process after the fact.

Examples

ExitCode can be returned from the main function of a crate, as it implements Termination:

use std::process::ExitCode;

fn main() -> ExitCode {
    if !check_foo() {
        return ExitCode::from(42);
    }

    ExitCode::SUCCESS
}
Run

Implementations

The canonical ExitCode for successful termination on this platform.

Note that a ()-returning main implicitly results in a successful termination, so there’s no need to return this from main unless you’re also returning other possible codes.

The canonical ExitCode for unsuccessful termination on this platform.

If you’re only returning this and SUCCESS from main, consider instead returning Err(_) and Ok(()) respectively, which will return the same codes (but will also eprintln! the error).

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Construct an ExitCode from an arbitrary u8 value.

Is called to get the representation of the value as status code. This status code is returned to the operating system. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.