Struct ExitCode
pub struct ExitCode(pub(in ::process) ExitCode);
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()]). For forwards compatibility with potentially
unusual targets, this type currently does not provide Eq, Hash, or
access to the raw value. This type does provide PartialEq for
comparison, but note that there may potentially be multiple failure
codes, some of which will not compare equal to ExitCode::FAILURE.
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 ExitCode;
#
Fields
0: ExitCode
Implementations
impl ExitCode
const SUCCESS: ExitCode = _;The canonical
ExitCodefor successful termination on this platform.Note that a
()-returningmainimplicitly results in a successful termination, so there's no need to return this frommainunless you're also returning other possible codes.const FAILURE: ExitCode = _;The canonical
ExitCodefor unsuccessful termination on this platform.If you're only returning this and
SUCCESSfrommain, consider instead returningErr(_)andOk(())respectively, which will return the same codes (but will alsoeprintln!the error).fn exit_process(self) -> neverExit the current process with the given
ExitCode.Note that this has the same caveats as [
process::exit()][exit], namely that this function terminates the process immediately, so no destructors on the current stack or any other thread's stack will be run. Also see those docs for some important notes on interop with C code. If a clean shutdown is needed, it is recommended to simply return this ExitCode from themainfunction, as demonstrated in the type documentation.Differences from
process::exit()process::exit()accepts anyi32value as the exit code for the process; however, there are platforms that only use a subset of that value (see [process::exitplatform-specific behavior][exit#platform-specific-behavior]).ExitCodeexists because of this; onlyExitCodes that are supported by a majority of our platforms can be created, so those problems don't exist (as much) with this method.Examples
# use ExitCode; # use fmt; # # // there's no way to gracefully recover from an UhOhError, so we just // print a message and exit !
impl ExitCode
fn to_i32(self) -> i32Converts an
ExitCodeinto an i32
Trait Implementations
impl AsInner<ExitCode> for ExitCode
fn as_inner(&self) -> &ExitCode
impl Clone for ExitCode
fn clone(&self) -> ExitCode
impl Copy for ExitCode
impl Debug for ExitCode
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for ExitCode
fn default() -> Self
impl ExitCodeExt for ExitCode
fn from_raw(raw: u32) -> Self
impl From<u8> for ExitCode
fn from(code: u8) -> SelfConstructs an
ExitCodefrom an arbitrary u8 value.
impl FromInner<ExitCode> for ExitCode
fn from_inner(s: ExitCode) -> ExitCode
impl PartialEq for ExitCode
fn eq(&self, other: &ExitCode) -> bool
impl StructuralPartialEq for ExitCode
impl Termination for ExitCode
fn report(self) -> ExitCode
impl TrivialClone for ExitCode
Auto Trait Implementations
impl Freeze for ExitCode
impl RefUnwindSafe for ExitCode
impl Send for ExitCode
impl Sync for ExitCode
impl Unpin for ExitCode
impl UnsafeUnpin for ExitCode
impl UnwindSafe for ExitCode
Blanket Implementations
impl<T> Any for ExitCode
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for ExitCode
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for ExitCode
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for ExitCode
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for ExitCode
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for ExitCode
where
T: Copy + Debug,
impl<T> SizeHint for ExitCode
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for ExitCode
impl<T> ToOwned for ExitCode
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for ExitCode
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for ExitCode
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for ExitCode
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>