Skip to content

Commit

Permalink
Redundant Option Checks, Unwrap Safety (#1892)
Browse files Browse the repository at this point in the history
Redundant Option Checks, unwrap Safety, unnecessary Lifetimes, Rust often infers lifetimes automatically

---------

Co-authored-by: Quied <[email protected]>
  • Loading branch information
sharma-shray and Quied authored Nov 9, 2024
1 parent 4f21731 commit d90f6b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 10 additions & 3 deletions src/parse_styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ pub fn parse_styles(opt: &cli::Opt) -> HashMap<String, Style> {
make_misc_styles(opt, &mut styles);

let mut resolved_styles = resolve_style_references(styles, opt);
resolved_styles.get_mut("minus-emph-style").unwrap().is_emph = true;
resolved_styles.get_mut("plus-emph-style").unwrap().is_emph = true;
resolved_styles
.get_mut("minus-emph-style")
.unwrap_or_else(|| panic!("minus-emph-style not found in resolved styles"))
.is_emph = true;

resolved_styles
.get_mut("plus-emph-style")
.unwrap_or_else(|| panic!("plus-emph-style not found in resolved styles"))
.is_emph = true;
resolved_styles
}

Expand Down Expand Up @@ -114,7 +121,7 @@ fn parse_as_reference_to_git_config(style_string: &str, opt: &cli::Opt) -> Style
}
}

fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleReference>) {
fn make_hunk_styles(opt: &cli::Opt, styles: &mut HashMap<&str, StyleReference>) {
let color_mode = opt.computed.color_mode;
let true_color = opt.computed.true_color;
let minus_style = style_from_str(
Expand Down
14 changes: 4 additions & 10 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,11 @@ impl fmt::Debug for AnsiTermStyleEqualityKey {
}

fn ansi_term_color_equality(a: Option<ansi_term::Color>, b: Option<ansi_term::Color>) -> bool {
match (a, b) {
(None, None) => true,
(None, Some(_)) => false,
(Some(_), None) => false,
(Some(a), Some(b)) => {
if a == b {
true
} else {
ansi_term_16_color_equality(a, b) || ansi_term_16_color_equality(b, a)
}
match a.zip(b) {
Some((a, b)) => {
a == b || ansi_term_16_color_equality(a, b) || ansi_term_16_color_equality(b, a)
}
None => a.is_none() && b.is_none(),
}
}

Expand Down

0 comments on commit d90f6b5

Please sign in to comment.