sdivi_core/exit_code.rs
1/// Exit codes for the `sdivi` binary.
2///
3/// These are **public API** — adding a variant or reusing an existing code
4/// is a breaking change requiring a major version bump.
5///
6/// # Examples
7///
8/// ```rust
9/// use sdivi_core::ExitCode;
10///
11/// assert_eq!(ExitCode::Success as i32, 0);
12/// assert_eq!(ExitCode::ThresholdExceeded as i32, 10);
13/// ```
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15#[repr(i32)]
16pub enum ExitCode {
17 /// Successful run; no threshold breaches.
18 Success = 0,
19 /// Runtime error (unexpected I/O failure, internal invariant violated).
20 RuntimeError = 1,
21 /// Configuration error (malformed TOML, invalid value, missing `expires`).
22 ConfigError = 2,
23 /// Analysis error (e.g. no grammar available for any detected language).
24 AnalysisError = 3,
25 /// At least one threshold was exceeded. Emitted **only** by `sdivi check`.
26 ThresholdExceeded = 10,
27}
28
29impl ExitCode {
30 /// Returns the integer exit-code value.
31 ///
32 /// # Examples
33 ///
34 /// ```rust
35 /// use sdivi_core::ExitCode;
36 ///
37 /// assert_eq!(ExitCode::ThresholdExceeded.as_i32(), 10);
38 /// ```
39 pub fn as_i32(self) -> i32 {
40 self as i32
41 }
42}
43
44impl From<ExitCode> for i32 {
45 fn from(code: ExitCode) -> i32 {
46 code as i32
47 }
48}