Skip to content

Commit

Permalink
fix(clippy): Derive Default where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jalil-salame authored and wez committed Mar 15, 2023
1 parent fc656c0 commit c6dc38b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 88 deletions.
18 changes: 4 additions & 14 deletions config/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 10 additions & 35 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,22 +1572,17 @@ 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,
BlinkingBar,
SteadyBar,
}

impl Default for DefaultCursorStyle {
fn default() -> Self {
DefaultCursorStyle::SteadyBlock
}
}

impl DefaultCursorStyle {
pub fn effective_shape(self, shape: CursorShape) -> CursorShape {
match shape {
Expand Down Expand Up @@ -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,
Expand All @@ -1682,22 +1672,17 @@ 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,
/// Hold the pane until it is explicitly closed
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down
18 changes: 4 additions & 14 deletions config/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
9 changes: 2 additions & 7 deletions config/src/frontend.rs
Original file line number Diff line number Diff line change
@@ -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 <https://docs.rs/wgpu/latest/wgpu/struct.AdapterInfo.html>
#[derive(Debug, Clone, FromDynamic, ToDynamic)]
pub struct GpuInfo {
Expand Down
9 changes: 2 additions & 7 deletions wezterm-dynamic/src/fromdynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 1 addition & 11 deletions window/src/os/wayland/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rc<FontConfiguration>>,
pub config: Option<ConfigHandle>,
Expand All @@ -56,16 +56,6 @@ impl ConceptConfig {
}
}

impl Default for ConceptConfig {
fn default() -> ConceptConfig {
ConceptConfig {
font_config: None,
default_frame: WindowFrameConfig::default(),
config: None,
}
}
}

/*
* Utilities
*/
Expand Down

0 comments on commit c6dc38b

Please sign in to comment.