Simplify merging of options
@@ -74,42 +74,16 @@ impl Options {
/// will supercede a `Some` in `self`
// TODO: Maybe a good candidate for a macro?
pub fn merge(&self, other: Options) -> Options {
- let simplified_ui = if other.simplified_ui {
- true
- } else {
- self.simplified_ui
- };
-
- let default_mode = match other.default_mode {
- None => self.default_mode,
- other => other,
- };
-
- let default_shell = match other.default_shell {
- None => self.default_shell.clone(),
- other => other,
- };
+ let merge_bool = |opt_other, opt_self| if opt_other { true } else { opt_self };
- let layout_dir = match other.layout_dir {
- None => self.layout_dir.clone(),
- other => other,
- };
-
- let theme = match other.theme {
- None => self.theme.clone(),
- other => other,
- };
-
- let disable_mouse_mode = if other.disable_mouse_mode {
- true
- } else {
- self.disable_mouse_mode
- };
+ let simplified_ui = merge_bool(other.simplified_ui, self.simplified_ui);
+ let disable_mouse_mode = merge_bool(other.disable_mouse_mode, self.disable_mouse_mode);
- let on_force_close = match other.on_force_close {
- None => self.on_force_close,
- other => other,
- };
+ let default_mode = other.default_mode.or(self.default_mode);
+ let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
+ let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone());
+ let theme = other.theme.or_else(|| self.theme.clone());
+ let on_force_close = other.on_force_close.or(self.on_force_close);
Options {
simplified_ui,
