From 2689bccbb947c7d098f5e8843b26401ee4672168 Mon Sep 17 00:00:00 2001 From: Michael Doronin Date: Tue, 9 Nov 2021 15:13:55 +0300 Subject: [PATCH] Use combinators instead of manual code --- src/editor/cursor.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/editor/cursor.rs b/src/editor/cursor.rs index 14514a9..09c1ab9 100644 --- a/src/editor/cursor.rs +++ b/src/editor/cursor.rs @@ -66,25 +66,19 @@ impl Cursor { } pub fn foreground(&self, default_colors: &Colors) -> Color4f { - if let Some(style) = &self.style { - style - .colors - .foreground - .unwrap_or_else(|| default_colors.background.unwrap()) - } else { - default_colors.background.unwrap() - } + self + .style + .as_ref() + .and_then(|s| s.colors.foreground) + .unwrap_or(default_colors.background.unwrap()) } pub fn background(&self, default_colors: &Colors) -> Color4f { - if let Some(style) = &self.style { - style - .colors - .background - .unwrap_or_else(|| default_colors.foreground.unwrap()) - } else { - default_colors.foreground.unwrap() - } + self + .style + .as_ref() + .and_then(|s| s.colors.background) + .unwrap_or(default_colors.foreground.unwrap()) } pub fn change_mode(&mut self, cursor_mode: &CursorMode, styles: &HashMap>) {