From c6dc38b7f3c9ef340ab1aa4fad06efee96858d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Tue, 14 Mar 2023 22:08:31 -0300 Subject: [PATCH] fix(clippy): Derive Default where possible --- config/src/background.rs | 18 +++--------- config/src/config.rs | 45 +++++++----------------------- config/src/font.rs | 18 +++--------- config/src/frontend.rs | 9 ++---- wezterm-dynamic/src/fromdynamic.rs | 9 ++---- window/src/os/wayland/frame.rs | 12 +------- 6 files changed, 23 insertions(+), 88 deletions(-) diff --git a/config/src/background.rs b/config/src/background.rs index 562b219de..e07603bbc 100644 --- a/config/src/background.rs +++ b/config/src/background.rs @@ -290,33 +290,23 @@ impl Default for BackgroundOrigin { } } -#[derive(Debug, Copy, Clone, FromDynamic, ToDynamic, PartialEq)] +#[derive(Debug, Copy, Clone, FromDynamic, ToDynamic, PartialEq, Default)] pub enum Interpolation { + #[default] Linear, Basis, CatmullRom, } -impl Default for Interpolation { - fn default() -> Self { - Interpolation::Linear - } -} - -#[derive(Debug, Copy, Clone, FromDynamic, ToDynamic, PartialEq)] +#[derive(Debug, Copy, Clone, FromDynamic, ToDynamic, PartialEq, Default)] pub enum BlendMode { + #[default] Rgb, LinearRgb, Hsv, Oklab, } -impl Default for BlendMode { - fn default() -> Self { - BlendMode::Rgb - } -} - #[derive(Debug, Copy, Clone, FromDynamic, ToDynamic, PartialEq)] pub enum GradientOrientation { Horizontal, diff --git a/config/src/config.rs b/config/src/config.rs index 18e80313b..95e68779e 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -1572,9 +1572,10 @@ fn default_inactive_pane_hsb() -> HsbTransform { } } -#[derive(FromDynamic, ToDynamic, Clone, Copy, Debug)] +#[derive(FromDynamic, ToDynamic, Clone, Copy, Debug, Default)] pub enum DefaultCursorStyle { BlinkingBlock, + #[default] SteadyBlock, BlinkingUnderline, SteadyUnderline, @@ -1582,12 +1583,6 @@ pub enum DefaultCursorStyle { SteadyBar, } -impl Default for DefaultCursorStyle { - fn default() -> Self { - DefaultCursorStyle::SteadyBlock - } -} - impl DefaultCursorStyle { pub fn effective_shape(self, shape: CursorShape) -> CursorShape { match shape { @@ -1648,20 +1643,15 @@ pub enum NewlineCanon { CarriageReturnAndLineFeed, } -#[derive(FromDynamic, ToDynamic, Clone, Copy, Debug)] +#[derive(FromDynamic, ToDynamic, Clone, Copy, Debug, Default)] pub enum WindowCloseConfirmation { + #[default] AlwaysPrompt, NeverPrompt, // TODO: something smart where we see whether the // running programs are stateful } -impl Default for WindowCloseConfirmation { - fn default() -> Self { - WindowCloseConfirmation::AlwaysPrompt - } -} - struct PathPossibility { path: PathBuf, is_required: bool, @@ -1682,9 +1672,10 @@ impl PathPossibility { } /// Behavior when the program spawned by wezterm terminates -#[derive(Debug, FromDynamic, ToDynamic, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, FromDynamic, ToDynamic, Clone, Copy, PartialEq, Eq, Default)] pub enum ExitBehavior { /// Close the associated pane + #[default] Close, /// Close the associated pane if the process was successful CloseOnCleanExit, @@ -1692,12 +1683,6 @@ pub enum ExitBehavior { Hold, } -impl Default for ExitBehavior { - fn default() -> Self { - ExitBehavior::Close - } -} - #[derive(Debug, FromDynamic, ToDynamic, Clone, Copy, PartialEq, Eq)] pub enum DroppedFileQuoting { /// No quoting is performed, the file name is passed through as-is @@ -1762,11 +1747,12 @@ fn default_line_to_ele_shape_cache_size() -> usize { 1024 } -#[derive(Debug, ToDynamic, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, ToDynamic, Clone, Copy, PartialEq, Eq, Default)] pub enum BoldBrightening { /// Bold doesn't influence palette selection No, /// Bold Shifts palette from 0-7 to 8-15 and preserves bold font + #[default] BrightAndBold, /// Bold Shifts palette from 0-7 to 8-15 and removes bold intensity BrightOnly, @@ -1795,26 +1781,15 @@ impl FromDynamic for BoldBrightening { } } -impl Default for BoldBrightening { - fn default() -> Self { - BoldBrightening::BrightAndBold - } -} - -#[derive(Debug, FromDynamic, ToDynamic, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, FromDynamic, ToDynamic, Clone, Copy, PartialEq, Eq, Default)] pub enum ImePreeditRendering { /// IME preedit is rendered by WezTerm itself + #[default] Builtin, /// IME preedit is rendered by system System, } -impl Default for ImePreeditRendering { - fn default() -> Self { - ImePreeditRendering::Builtin - } -} - fn validate_row_or_col(value: &u16) -> Result<(), String> { if *value < 1 { Err("initial_cols and initial_rows must be non-zero".to_string()) diff --git a/config/src/font.rs b/config/src/font.rs index 07b01eb98..2c638fa1d 100644 --- a/config/src/font.rs +++ b/config/src/font.rs @@ -662,29 +662,19 @@ impl Default for FontLocatorSelection { } } -#[derive(Debug, Clone, Copy, FromDynamic, ToDynamic)] +#[derive(Debug, Clone, Copy, FromDynamic, ToDynamic, Default)] pub enum FontRasterizerSelection { + #[default] FreeType, } -impl Default for FontRasterizerSelection { - fn default() -> Self { - FontRasterizerSelection::FreeType - } -} - -#[derive(Debug, Clone, Copy, FromDynamic, ToDynamic)] +#[derive(Debug, Clone, Copy, FromDynamic, ToDynamic, Default)] pub enum FontShaperSelection { Allsorts, + #[default] Harfbuzz, } -impl Default for FontShaperSelection { - fn default() -> Self { - FontShaperSelection::Harfbuzz - } -} - #[cfg(test)] mod test { use super::*; diff --git a/config/src/frontend.rs b/config/src/frontend.rs index 21985db64..5a54add03 100644 --- a/config/src/frontend.rs +++ b/config/src/frontend.rs @@ -1,19 +1,14 @@ use luahelper::impl_lua_conversion_dynamic; use wezterm_dynamic::{FromDynamic, ToDynamic}; -#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic, Default)] pub enum FrontEndSelection { + #[default] OpenGL, WebGpu, Software, } -impl Default for FrontEndSelection { - fn default() -> Self { - FrontEndSelection::OpenGL - } -} - /// Corresponds to #[derive(Debug, Clone, FromDynamic, ToDynamic)] pub struct GpuInfo { diff --git a/wezterm-dynamic/src/fromdynamic.rs b/wezterm-dynamic/src/fromdynamic.rs index 578faab67..ee7521bee 100644 --- a/wezterm-dynamic/src/fromdynamic.rs +++ b/wezterm-dynamic/src/fromdynamic.rs @@ -7,22 +7,17 @@ use std::hash::Hash; /// Specify how FromDynamic will treat unknown fields /// when converting from Value to a given target type -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)] pub enum UnknownFieldAction { /// Don't check, don't warn, don't raise an error Ignore, /// Emit a log::warn log + #[default] Warn, /// Return an Error Deny, } -impl Default for UnknownFieldAction { - fn default() -> UnknownFieldAction { - UnknownFieldAction::Warn - } -} - /// Specify various options for FromDynamic::from_dynamic #[derive(Copy, Clone, Debug, Default)] pub struct FromDynamicOptions { diff --git a/window/src/os/wayland/frame.rs b/window/src/os/wayland/frame.rs index cfbf2f4e9..cc22a83e1 100644 --- a/window/src/os/wayland/frame.rs +++ b/window/src/os/wayland/frame.rs @@ -40,7 +40,7 @@ const BORDER_SIZE: u32 = 12; const HEADER_SIZE: u32 = 30; /// Configuration for ConceptFrame -#[derive(Clone)] +#[derive(Clone, Default)] pub struct ConceptConfig { pub font_config: Option>, pub config: Option, @@ -56,16 +56,6 @@ impl ConceptConfig { } } -impl Default for ConceptConfig { - fn default() -> ConceptConfig { - ConceptConfig { - font_config: None, - default_frame: WindowFrameConfig::default(), - config: None, - } - } -} - /* * Utilities */