exit_codes.rs
This file
Path
src/exit_codes.rs
74 lines · 1.8 KiB · Rust
Last changed by
Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
History of this fileTake it
The walk stopped after 200 commits: lines older than daf3046 point at it.
Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 1–3why, one step back1#[derive(Debug, Clone, Copy, PartialEq)]2pub enum ExitCode {3 Success,Add -q/--quiet/--has-match flag (#813)Asha20before adoption334488c
line 4why, one step back4 HasResults(bool),Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 5–8why, one step back5 GeneralError,6 KilledBySigint,7}8Fix clippy warningsDavid Peterbefore adoption2a2126c
lines 9–11why, one step back9impl From<ExitCode> for i32 {10 fn from(code: ExitCode) -> Self {11 match code {Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
line 12why, one step back12 ExitCode::Success => 0,Add -q/--quiet/--has-match flag (#813)Asha20before adoption334488c
line 13why, one step back13 ExitCode::HasResults(has_results) => !has_results as i32,Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 14–20why, one step back14 ExitCode::GeneralError => 1,15 ExitCode::KilledBySigint => 130,16 }17 }18}1920impl ExitCode {Fix clippy warningsDavid Peterbefore adoption2a2126c
line 21why, one step back21 fn is_error(self) -> bool {Add -q/--quiet/--has-match flag (#813)Asha20before adoption334488c
line 22why, one step back22 i32::from(self) != 0Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 23–25why, one step back23 }24}25Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
lines 26–27why, one step back26pub fn merge_exitcodes(results: impl IntoIterator<Item = ExitCode>) -> ExitCode {27 if results.into_iter().any(ExitCode::is_error) {Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 28–38why, one step back28 return ExitCode::GeneralError;29 }30 ExitCode::Success31}3233#[cfg(test)]34mod tests {35 use super::*;3637 #[test]38 fn success_when_no_results() {Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 39why, one step back39 assert_eq!(merge_exitcodes([]), ExitCode::Success);Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 40–44why, one step back40 }4142 #[test]43 fn general_error_if_at_least_one_error() {44 assert_eq!(Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 45why, one step back45 merge_exitcodes([ExitCode::GeneralError]),Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 46–48why, one step back46 ExitCode::GeneralError47 );48 assert_eq!(Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 49why, one step back49 merge_exitcodes([ExitCode::KilledBySigint]),Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 50–52why, one step back50 ExitCode::GeneralError51 );52 assert_eq!(Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 53why, one step back53 merge_exitcodes([ExitCode::KilledBySigint, ExitCode::Success]),Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 54–56why, one step back54 ExitCode::GeneralError55 );56 assert_eq!(Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 57why, one step back57 merge_exitcodes([ExitCode::Success, ExitCode::GeneralError]),Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 58–60why, one step back58 ExitCode::GeneralError59 );60 assert_eq!(Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 61why, one step back61 merge_exitcodes([ExitCode::GeneralError, ExitCode::KilledBySigint]),Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 62–67why, one step back62 ExitCode::GeneralError63 );64 }6566 #[test]67 fn success_if_no_error() {Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 68why, one step back68 assert_eq!(merge_exitcodes([ExitCode::Success]), ExitCode::Success);Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
line 69why, one step back69 assert_eq!(Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 70why, one step back70 merge_exitcodes([ExitCode::Success, ExitCode::Success]),Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 71–74why, one step back71 ExitCode::Success72 );73 }74}