Просмотр исходного кода

Use 0 and 1 rather than EXIT_SUCCESS/FAILURE

It doesn't seem right to use the EXIT_SUCCESS constant in one place, and a hard-coded 2 in another. What if they overlap?

Changing the success value to 0 should be OK, though, because the standard defines 0 as success, regardless of whether EXIT_SUCCESS is 0 or not.

Also, the values have become i32s. The Rust function std::process::exit takes an i32, so there's not much point using anything else.
Benjamin Sago 5 лет назад
Родитель
Сommit
df81a24dae
1 измененных файлов с 8 добавлено и 6 удалено
  1. 8 6
      src/bin/main.rs

+ 8 - 6
src/bin/main.rs

@@ -74,12 +74,14 @@ pub fn configure_logger() {
 }
 
 
-extern crate libc;
-#[allow(trivial_numeric_casts)]
 mod exits {
-    use libc::{self, c_int};
 
-    pub const SUCCESS:       c_int = libc::EXIT_SUCCESS;
-    pub const RUNTIME_ERROR: c_int = libc::EXIT_FAILURE;
-    pub const OPTIONS_ERROR: c_int = 3 as c_int;
+    /// Exit code for when exa runs OK.
+    pub const SUCCESS: i32 = 0;
+
+    /// Exit code for when there was at least one I/O error during execution.
+    pub const RUNTIME_ERROR: i32 = 1;
+
+    /// Exit code for when the command-line options are invalid.
+    pub const OPTIONS_ERROR: i32 = 3;
 }