|
| 1 | +# proc-result |
| 2 | + |
| 3 | +A tiny cross-platform library containing exit status and code types. |
| 4 | + |
| 5 | +Unlike `std::process`, this crate does not require the standard library[^1], nor |
| 6 | +`libc`, and can create and interpret exit codes of non-current platforms. For |
| 7 | +example, on Windows, it can read and interpret exit codes that may have been |
| 8 | +recorded from a Linux process, or vice versa. |
| 9 | + |
| 10 | +[^1]: The `std` feature is enabled by default, but can be disabled. |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +Most users of the crate will use the `ToProcResult` trait, which converts the |
| 15 | +result a run of a subprocess to a `ProcResult`, either a successful or an error |
| 16 | +explaining what exit code or (on Unix platforms) the signal the subprocess was |
| 17 | +prematurely terminated with, and is constructed from a |
| 18 | +`std::process::ExitStatus`: |
| 19 | + |
| 20 | +```rust |
| 21 | +use proc_result::ToProcResult; |
| 22 | +use std::error::Error; |
| 23 | +use std::process::Command; |
| 24 | + |
| 25 | +fn main() -> Result<(), Box<dyn Error>> { |
| 26 | + let result = Command::new("ls").status()?.to_proc_result()?; |
| 27 | + Ok(()) |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +Advanced users, or users writing tests or interpreting exit codes from other |
| 32 | +platforms may import and use the platform-specific exit code types directly, |
| 33 | +from the `unix` or `windows` modules, respectively. For example, to create a |
| 34 | +Unix exit code from a raw integer: |
| 35 | + |
| 36 | +```rust |
| 37 | +use proc_result::unix::ExitCode; |
| 38 | + |
| 39 | +fn main() { |
| 40 | + let code = ExitCode::from_raw(1); |
| 41 | + if code.is_success() { |
| 42 | + println!("Command succeeded!"); |
| 43 | + } else { |
| 44 | + eprintln!("Command failed with exit code: {}", code); |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +## Features |
| 50 | + |
| 51 | +Name | Default | Description |
| 52 | +------- | ------- | ----------- |
| 53 | +`serde` | `false` | Enables serialization support for most types using `serde`. |
| 54 | +`std` | `true` | Enables compatibility with `std::process::ExitStatus`. |
0 commit comments