From 39dd6d764497fa6e264e52b040ba6105f9ca2d76 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 16 Jan 2022 22:13:22 +0100 Subject: [PATCH] clippy fixes --- egui/src/containers/collapsing_header.rs | 11 +--------- egui/src/util/id_type_map.rs | 28 ++++++++++++------------ egui/src/widgets/plot/items/values.rs | 10 +-------- egui_demo_lib/src/apps/demo/plot_demo.rs | 18 ++------------- egui_demo_lib/src/apps/demo/scrolling.rs | 8 +------ 5 files changed, 19 insertions(+), 56 deletions(-) diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index 0a1a31dd..6f05b26d 100644 --- a/egui/src/containers/collapsing_header.rs +++ b/egui/src/containers/collapsing_header.rs @@ -3,7 +3,7 @@ use std::hash::Hash; use crate::*; use epaint::{Shape, TextStyle}; -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] pub(crate) struct State { @@ -13,15 +13,6 @@ pub(crate) struct State { open_height: Option, } -impl Default for State { - fn default() -> Self { - Self { - open: false, - open_height: None, - } - } -} - impl State { pub fn load(ctx: &Context, id: Id) -> Option { ctx.memory().data.get_persisted(id) diff --git a/egui/src/util/id_type_map.rs b/egui/src/util/id_type_map.rs index 516ad8c4..50b55312 100644 --- a/egui/src/util/id_type_map.rs +++ b/egui/src/util/id_type_map.rs @@ -311,19 +311,19 @@ use crate::Id; /// map.insert_temp(a, 42); /// /// // `b` associated with an f64 and a `&'static str` -/// map.insert_persisted(b, 6.28); +/// map.insert_persisted(b, 13.37); /// map.insert_temp(b, "Hello World".to_string()); /// /// // we can retrieve all four values: /// assert_eq!(map.get_temp::(a), Some(3.14)); /// assert_eq!(map.get_temp::(a), Some(42)); -/// assert_eq!(map.get_temp::(b), Some(6.28)); +/// assert_eq!(map.get_temp::(b), Some(13.37)); /// assert_eq!(map.get_temp::(b), Some("Hello World".to_string())); /// /// // we can retrieve them like so also: /// assert_eq!(map.get_persisted::(a), Some(3.14)); /// assert_eq!(map.get_persisted::(a), Some(42)); -/// assert_eq!(map.get_persisted::(b), Some(6.28)); +/// assert_eq!(map.get_persisted::(b), Some(13.37)); /// assert_eq!(map.get_temp::(b), Some("Hello World".to_string())); /// ``` #[derive(Clone, Debug, Default)] @@ -544,11 +544,11 @@ fn test_two_id_two_type() { let b = Id::new("b"); let mut map: IdTypeMap = Default::default(); - map.insert_persisted(a, 6.28); + map.insert_persisted(a, 13.37); map.insert_temp(b, 42); - assert_eq!(map.get_persisted::(a), Some(6.28)); + assert_eq!(map.get_persisted::(a), Some(13.37)); assert_eq!(map.get_persisted::(b), Some(42)); - assert_eq!(map.get_temp::(a), Some(6.28)); + assert_eq!(map.get_temp::(a), Some(13.37)); assert_eq!(map.get_temp::(b), Some(42)); } @@ -565,19 +565,19 @@ fn test_two_id_x_two_types() { map.insert_temp(a, 42); // `b` associated with an f64 and a `&'static str` - map.insert_persisted(b, 6.28); + map.insert_persisted(b, 13.37); map.insert_temp(b, "Hello World".to_string()); // we can retrieve all four values: assert_eq!(map.get_temp::(a), Some(3.14)); assert_eq!(map.get_temp::(a), Some(42)); - assert_eq!(map.get_temp::(b), Some(6.28)); + assert_eq!(map.get_temp::(b), Some(13.37)); assert_eq!(map.get_temp::(b), Some("Hello World".to_string())); // we can retrieve them like so also: assert_eq!(map.get_persisted::(a), Some(3.14)); assert_eq!(map.get_persisted::(a), Some(42)); - assert_eq!(map.get_persisted::(b), Some(6.28)); + assert_eq!(map.get_persisted::(b), Some(13.37)); assert_eq!(map.get_temp::(b), Some("Hello World".to_string())); } @@ -586,11 +586,11 @@ fn test_one_id_two_types() { let id = Id::new("a"); let mut map: IdTypeMap = Default::default(); - map.insert_persisted(id, 6.28); + map.insert_persisted(id, 13.37); map.insert_temp(id, 42); - assert_eq!(map.get_temp::(id), Some(6.28)); - assert_eq!(map.get_persisted::(id), Some(6.28)); + assert_eq!(map.get_temp::(id), Some(13.37)); + assert_eq!(map.get_persisted::(id), Some(13.37)); assert_eq!(map.get_temp::(id), Some(42)); // ------------ @@ -601,8 +601,8 @@ fn test_one_id_two_types() { assert_eq!(map.get_temp::(id), None); // Other type is still there, even though it is the same if: - assert_eq!(map.get_temp::(id), Some(6.28)); - assert_eq!(map.get_persisted::(id), Some(6.28)); + assert_eq!(map.get_temp::(id), Some(13.37)); + assert_eq!(map.get_persisted::(id), Some(13.37)); // But we can still remove the last: map.remove::(id); diff --git a/egui/src/widgets/plot/items/values.rs b/egui/src/widgets/plot/items/values.rs index 01410c91..95662867 100644 --- a/egui/src/widgets/plot/items/values.rs +++ b/egui/src/widgets/plot/items/values.rs @@ -139,20 +139,12 @@ impl Default for Orientation { // ---------------------------------------------------------------------------- +#[derive(Default)] pub struct Values { pub(super) values: Vec, generator: Option, } -impl Default for Values { - fn default() -> Self { - Self { - values: Vec::new(), - generator: None, - } - } -} - impl Values { pub fn from_values(values: Vec) -> Self { Self { diff --git a/egui_demo_lib/src/apps/demo/plot_demo.rs b/egui_demo_lib/src/apps/demo/plot_demo.rs index 4e55e4bd..00f34ab1 100644 --- a/egui_demo_lib/src/apps/demo/plot_demo.rs +++ b/egui_demo_lib/src/apps/demo/plot_demo.rs @@ -237,19 +237,11 @@ impl Widget for &mut MarkerDemo { } } -#[derive(PartialEq)] +#[derive(Default, PartialEq)] struct LegendDemo { config: Legend, } -impl Default for LegendDemo { - fn default() -> Self { - Self { - config: Legend::default(), - } - } -} - impl LegendDemo { fn line_with_slope(slope: f64) -> Line { Line::new(Values::from_explicit_callback(move |x| slope * x, .., 100)) @@ -381,15 +373,9 @@ impl Widget for &mut ItemsDemo { } } -#[derive(PartialEq)] +#[derive(Default, PartialEq)] struct InteractionDemo {} -impl Default for InteractionDemo { - fn default() -> Self { - Self {} - } -} - impl Widget for &mut InteractionDemo { fn ui(self, ui: &mut Ui) -> Response { let plot = Plot::new("interaction_demo").height(300.0); diff --git a/egui_demo_lib/src/apps/demo/scrolling.rs b/egui_demo_lib/src/apps/demo/scrolling.rs index 485f03e1..7c69a726 100644 --- a/egui_demo_lib/src/apps/demo/scrolling.rs +++ b/egui_demo_lib/src/apps/demo/scrolling.rs @@ -253,17 +253,11 @@ impl super::View for ScrollTo { #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] -#[derive(PartialEq)] +#[derive(Default, PartialEq)] struct ScrollStickTo { n_items: usize, } -impl Default for ScrollStickTo { - fn default() -> Self { - Self { n_items: 0 } - } -} - impl super::View for ScrollStickTo { fn ui(&mut self, ui: &mut Ui) { ui.label("Rows enter from the bottom, we want the scroll handle to start and stay at bottom unless moved");