Struct proc_exit::Code

source ·
pub struct Code(_);
Expand description

Process exit code.

Common exit codes:

Implementations§

source§

impl Code

source

pub const SUCCESS: Code = _

The process exited successfully.

source

pub const FAILURE: Code = _

Generic failure.

source

pub const fn new(code: i32) -> Self

Create a custom error code

source

pub fn from_status(status: ExitStatus) -> Self

Converts std::process::ExitStatus to Code.

On Unix, if the process was terminated by a fatal signal, the corresponding signal exit code is returned.

source§

impl Code

source

pub fn process_exit(self) -> !

exit now!

source

pub fn ok(self) -> ExitResult

Convert to Result

source

pub fn as_exit(self) -> Exit

Convert to Exit error type

source

pub fn with_message<D: Display + 'static>(self, msg: D) -> Exit

Add user-visible message (like an Error)

source§

impl Code

source

pub fn as_exit_code(self) -> Option<ExitCode>

Convert to `ExitCode

source

pub const fn as_raw(self) -> i32

Convert to raw value

source

pub const fn as_portable(self) -> Option<u8>

Convert to portable, raw value

source

pub const fn is_ok(self) -> bool

Determines if the provided std::process::ExitStatus was successful.

Example:

use std::process;

let exit_status = process::Command::new("true")
    .status()
    .expect("failed to run true(1)");
assert!(proc_exit::Code::from_status(exit_status).is_ok());
source

pub const fn is_err(self) -> bool

Determines if the provided std::process::ExitStatus was unsuccessful.

Example:

use std::process;

let exit_status = process::Command::new("false")
    .status()
    .expect("failed to run false(1)");
assert!(proc_exit::Code::from_status(exit_status).is_err());
source

pub const fn is_portable(self) -> bool

Test if provided exit code is portable across platforms.

While Windows has wider types for return codes, Unix OS’s tend to only support 8-bits, stripping off the higher order bits.

Trait Implementations§

source§

impl Clone for Code

source§

fn clone(&self) -> Code

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Code

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Code

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<ExitStatus> for Code

Converts std::process::ExitStatus to an exit code by looking at its ExitStatus::code() value.

On Unix, if the process was terminated by a fatal signal, the corresponding signal exit code is returned.

source§

fn from(status: ExitStatus) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Code

Converts an i32 primitive integer to an exit code.

source§

fn from(n: i32) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Code> for Code

source§

fn eq(&self, other: &Code) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Termination for Code

source§

fn report(self) -> ExitCode

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

impl Copy for Code

source§

impl Eq for Code

source§

impl StructuralEq for Code

source§

impl StructuralPartialEq for Code

Auto Trait Implementations§

§

impl RefUnwindSafe for Code

§

impl Send for Code

§

impl Sync for Code

§

impl Unpin for Code

§

impl UnwindSafe for Code

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.