diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index 72b02371..261b4412 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -229,7 +229,7 @@ impl Config { // Start a transaction (to set multiple configs at the same time) #[inline] - pub fn transaction(&self) -> ConfigTransaction { + pub fn transaction(&self) -> ConfigTransaction<'_> { ConfigTransaction { config: self, updates: Mutex::new(Vec::new()), diff --git a/cosmic-config/src/subscription.rs b/cosmic-config/src/subscription.rs index 88f8bfa2..32f48849 100644 --- a/cosmic-config/src/subscription.rs +++ b/cosmic-config/src/subscription.rs @@ -93,7 +93,7 @@ async fn start_listening { let update = crate::Update { - errors: errors, + errors, keys: Vec::new(), config: t.clone(), }; diff --git a/cosmic-theme/src/model/theme.rs b/cosmic-theme/src/model/theme.rs index d1d3ae0a..1f94f5a2 100644 --- a/cosmic-theme/src/model/theme.rs +++ b/cosmic-theme/src/model/theme.rs @@ -814,7 +814,7 @@ pub struct ThemeBuilder { impl Default for ThemeBuilder { fn default() -> Self { Self { - palette: DARK_PALETTE.to_owned().into(), + palette: DARK_PALETTE.to_owned(), spacing: Spacing::default(), corner_radii: CornerRadii::default(), neutral_tint: Default::default(), @@ -1077,7 +1077,7 @@ impl ThemeBuilder { component_pressed_overlay = component_hovered_overlay; component_pressed_overlay.alpha = 0.2; - let container = Container::new( + Container::new( Component::component( component_base, accent, @@ -1101,9 +1101,7 @@ impl ThemeBuilder { ), get_small_widget_color(base_index, 5, &neutral_steps, &control_steps_array[6]), is_high_contrast, - ); - - container + ) }; let accent_text = if is_dark { diff --git a/cosmic-theme/src/steps.rs b/cosmic-theme/src/steps.rs index 6c0779c2..143cf532 100644 --- a/cosmic-theme/src/steps.rs +++ b/cosmic-theme/src/steps.rs @@ -93,7 +93,7 @@ pub fn get_text( let index = get_index(base_index, 70, step_array.len(), is_dark) .or_else(|| get_index(base_index, 50, step_array.len(), is_dark)) - .unwrap_or_else(|| if is_dark { 99 } else { 0 }); + .unwrap_or(if is_dark { 99 } else { 0 }); *step_array.get(index).unwrap_or(fallback) } diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index c53bb6a6..2e4b3cb9 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -114,7 +114,7 @@ where ( Self::new(model), - Task::batch(vec![ + Task::batch([ command, iced_runtime::window::run_with_handle(id, init_windowing_system), ]), @@ -665,23 +665,21 @@ impl Cosmic { bottom_left: radii[3].round() as u32, }; let rounded = !self.app.core().window.sharp_corners; - return Task::batch(vec![ - corner_radius( - id, - if rounded { - Some(cur_rad) - } else { - let rad_0 = t.radius_0(); - Some(CornerRadius { - top_left: rad_0[0].round() as u32, - top_right: rad_0[1].round() as u32, - bottom_right: rad_0[2].round() as u32, - bottom_left: rad_0[3].round() as u32, - }) - }, - ) - .discard(), - ]); + return Task::batch([corner_radius( + id, + if rounded { + Some(cur_rad) + } else { + let rad_0 = t.radius_0(); + Some(CornerRadius { + top_left: rad_0[0].round() as u32, + top_right: rad_0[1].round() as u32, + bottom_right: rad_0[2].round() as u32, + bottom_left: rad_0[3].round() as u32, + }) + }, + ) + .discard()]); } } @@ -1061,7 +1059,7 @@ impl Cosmic { if core.exit_on_main_window_closed && core.main_window_id().is_some_and(|m_id| id == m_id) { - ret = Task::batch(vec![iced::exit::>()]); + ret = Task::batch([iced::exit::>()]); } return ret; } @@ -1231,7 +1229,7 @@ impl Cosmic { // TODO do we need per window sharp corners? let rounded = !self.app.core().window.sharp_corners; - return Task::batch(vec![ + return Task::batch([ corner_radius( id, if rounded { @@ -1326,9 +1324,9 @@ impl Cosmic { >, ) -> Task> { use iced_winit::SurfaceIdWrapper; - *self.opened_surfaces.entry(id.clone()).or_insert_with(|| 0) += 1; + *self.opened_surfaces.entry(id).or_insert(0) += 1; self.surface_views.insert( - id.clone(), + id, ( None, // TODO parent for window, platform specific option maybe? SurfaceIdWrapper::Window(id), diff --git a/src/app/mod.rs b/src/app/mod.rs index a2f8d6ad..eaf0bae6 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -420,10 +420,10 @@ where } /// Constructs the view for the main window. - fn view(&self) -> Element; + fn view(&self) -> Element<'_, Self::Message>; /// Constructs views for other windows. - fn view_window(&self, id: window::Id) -> Element { + fn view_window(&self, id: window::Id) -> Element<'_, Self::Message> { panic!("no view for window {id:?}"); } diff --git a/src/desktop.rs b/src/desktop.rs index d41f29a2..687fa6c4 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -136,7 +136,7 @@ pub fn load_applications_for_app_ids<'a>( } #[cfg(not(windows))] -pub fn load_desktop_file<'a>(locales: &'a [String], path: PathBuf) -> Option { +pub fn load_desktop_file(locales: &[String], path: PathBuf) -> Option { fde::DesktopEntry::from_path(path, Some(locales)) .ok() .map(|de| DesktopEntryData::from_desktop_entry(locales, de)) @@ -144,10 +144,7 @@ pub fn load_desktop_file<'a>(locales: &'a [String], path: PathBuf) -> Option( - locales: &'a [String], - de: fde::DesktopEntry, - ) -> DesktopEntryData { + pub fn from_desktop_entry(locales: &[String], de: fde::DesktopEntry) -> DesktopEntryData { let name = de .name(locales) .unwrap_or(Cow::Borrowed(&de.appid)) diff --git a/src/dialog/file_chooser/save.rs b/src/dialog/file_chooser/save.rs index cfb1382b..d7a2a34e 100644 --- a/src/dialog/file_chooser/save.rs +++ b/src/dialog/file_chooser/save.rs @@ -120,6 +120,12 @@ impl Dialog { } } +impl Default for Dialog { + fn default() -> Self { + Self::new() + } +} + #[cfg(feature = "xdg-portal")] mod portal { use super::Dialog; diff --git a/src/theme/mod.rs b/src/theme/mod.rs index f01180c1..b7e85237 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -22,15 +22,15 @@ pub type CosmicColor = ::palette::rgb::Srgba; pub type CosmicComponent = cosmic_theme::Component; pub type CosmicTheme = cosmic_theme::Theme; -pub static COSMIC_DARK: LazyLock = LazyLock::new(|| CosmicTheme::dark_default()); +pub static COSMIC_DARK: LazyLock = LazyLock::new(CosmicTheme::dark_default); pub static COSMIC_HC_DARK: LazyLock = - LazyLock::new(|| CosmicTheme::high_contrast_dark_default()); + LazyLock::new(CosmicTheme::high_contrast_dark_default); -pub static COSMIC_LIGHT: LazyLock = LazyLock::new(|| CosmicTheme::light_default()); +pub static COSMIC_LIGHT: LazyLock = LazyLock::new(CosmicTheme::light_default); pub static COSMIC_HC_LIGHT: LazyLock = - LazyLock::new(|| CosmicTheme::high_contrast_light_default()); + LazyLock::new(CosmicTheme::high_contrast_light_default); pub static TRANSPARENT_COMPONENT: LazyLock = LazyLock::new(|| Component { base: CosmicColor::new(0.0, 0.0, 0.0, 0.0), diff --git a/src/theme/style/iced.rs b/src/theme/style/iced.rs index c8dacbb9..32309860 100644 --- a/src/theme/style/iced.rs +++ b/src/theme/style/iced.rs @@ -898,12 +898,10 @@ impl toggler::Catalog for Theme { let mut active = toggler::Style { background: if matches!(status, toggler::Status::Active { is_toggled: true }) { cosmic.accent.base.into() + } else if cosmic.is_dark { + cosmic.palette.neutral_6.into() } else { - if cosmic.is_dark { - cosmic.palette.neutral_6.into() - } else { - cosmic.palette.neutral_5.into() - } + cosmic.palette.neutral_5.into() }, foreground: cosmic.palette.neutral_2.into(), border_radius: cosmic.radius_xl().into(), @@ -1166,11 +1164,7 @@ impl scrollable::Catalog for Theme { }, gap: None, }; - let small_widget_container = self - .current_container() - .small_widget - .clone() - .with_alpha(0.7); + let small_widget_container = self.current_container().small_widget.with_alpha(0.7); if matches!(class, Scrollable::Permanent) { a.horizontal_rail.background = @@ -1233,11 +1227,8 @@ impl scrollable::Catalog for Theme { }; if matches!(class, Scrollable::Permanent) { - let small_widget_container = self - .current_container() - .small_widget - .clone() - .with_alpha(0.7); + let small_widget_container = + self.current_container().small_widget.with_alpha(0.7); a.horizontal_rail.background = Some(Background::Color(small_widget_container.into())); diff --git a/src/widget/about.rs b/src/widget/about.rs index 9f2276c8..628f53c6 100644 --- a/src/widget/about.rs +++ b/src/widget/about.rs @@ -152,13 +152,11 @@ pub fn about<'a, Message: Clone + 'static>( let artists_section = section(&about.artists, fl!("artists")); let translators_section = section(&about.translators, fl!("translators")); let documenters_section = section(&about.documenters, fl!("documenters")); - let license_section = about.license.as_ref().and_then(|license| { + let license_section = about.license.as_ref().map(|license| { let url = about.license_url.as_deref().unwrap_or_default(); - Some( - widget::settings::section() - .title(fl!("license")) - .add(section_button(license, url)), - ) + widget::settings::section() + .title(fl!("license")) + .add(section_button(license, url)) }); let copyright = about.copyright.as_ref().map(widget::text::body); let comments = about.comments.as_ref().map(widget::text::body); diff --git a/src/widget/button/widget.rs b/src/widget/button/widget.rs index 3f5a1fdf..87233330 100644 --- a/src/widget/button/widget.rs +++ b/src/widget/button/widget.rs @@ -793,7 +793,7 @@ pub fn update<'a, Message: Clone>( } Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) | Event::Touch(touch::Event::FingerLifted { .. }) => { - if let Some(on_press) = on_press.clone() { + if let Some(on_press) = on_press { let state = state(); if state.is_pressed { @@ -816,9 +816,9 @@ pub fn update<'a, Message: Clone>( #[cfg(feature = "a11y")] Event::A11y(event_id, iced_accessibility::accesskit::ActionRequest { action, .. }) => { let state = state(); - if let Some(Some(on_press)) = (event_id == event_id - && matches!(action, iced_accessibility::accesskit::Action::Default)) - .then(|| on_press.clone()) + if let Some(on_press) = matches!(action, iced_accessibility::accesskit::Action::Default) + .then_some(on_press) + .flatten() { state.is_pressed = false; let msg = (on_press)(layout.virtual_offset(), layout.bounds()); @@ -828,7 +828,7 @@ pub fn update<'a, Message: Clone>( return event::Status::Captured; } Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => { - if let Some(on_press) = on_press.clone() { + if let Some(on_press) = on_press { let state = state(); if state.is_focused && key == keyboard::Key::Named(keyboard::key::Named::Enter) { state.is_pressed = true; diff --git a/src/widget/calendar.rs b/src/widget/calendar.rs index 303a1ed9..a1aace33 100644 --- a/src/widget/calendar.rs +++ b/src/widget/calendar.rs @@ -17,7 +17,7 @@ pub fn calendar( on_prev: impl Fn() -> M + 'static, on_next: impl Fn() -> M + 'static, first_day_of_week: Weekday, -) -> Calendar { +) -> Calendar<'_, M> { Calendar { model, on_select: Box::new(on_select), diff --git a/src/widget/color_picker/mod.rs b/src/widget/color_picker/mod.rs index a17625dc..536531a4 100644 --- a/src/widget/color_picker/mod.rs +++ b/src/widget/color_picker/mod.rs @@ -233,7 +233,7 @@ impl ColorPickerModel { pub fn builder( &self, on_update: fn(ColorPickerUpdate) -> Message, - ) -> ColorPickerBuilder { + ) -> ColorPickerBuilder<'_, Message> { ColorPickerBuilder { model: &self.segmented_model, active_color: self.active_color, diff --git a/src/widget/dropdown/multi/menu.rs b/src/widget/dropdown/multi/menu.rs index da103f8a..10b0d8d4 100644 --- a/src/widget/dropdown/multi/menu.rs +++ b/src/widget/dropdown/multi/menu.rs @@ -673,8 +673,8 @@ pub(super) enum OptionElement<'a, S, Item> { } impl Model { - pub(super) fn elements(&self) -> impl Iterator> + '_ { - let iterator = self.lists.iter().flat_map(|list| { + pub(super) fn elements(&self) -> impl Iterator> + '_ { + self.lists.iter().flat_map(|list| { let description = list .description .as_ref() @@ -686,9 +686,7 @@ impl Model { description .chain(options) .chain(std::iter::once(OptionElement::Separator)) - }); - - iterator + }) } fn element_heights( @@ -709,7 +707,7 @@ impl Model { text_line_height: f32, offset: f32, height: f32, - ) -> impl Iterator, f32)> + '_ { + ) -> impl Iterator, f32)> + '_ { let heights = self.element_heights(padding_vertical, text_line_height); let mut current = 0.0; diff --git a/src/widget/dropdown/multi/model.rs b/src/widget/dropdown/multi/model.rs index 12bf4269..f67f8edd 100644 --- a/src/widget/dropdown/multi/model.rs +++ b/src/widget/dropdown/multi/model.rs @@ -66,9 +66,7 @@ impl Model { } pub(super) fn next(&self) -> Option<&(S, Item)> { - let Some(item) = self.selected.as_ref() else { - return None; - }; + let item = self.selected.as_ref()?; let mut next = false; for list in &self.lists { diff --git a/src/widget/header_bar.rs b/src/widget/header_bar.rs index 3f4b5d88..01a8d559 100644 --- a/src/widget/header_bar.rs +++ b/src/widget/header_bar.rs @@ -293,11 +293,9 @@ impl Widget ) -> iced_accessibility::A11yTree { let c_layout = layout.children().next().unwrap(); let c_state = &state.children[0]; - let ret = self - .header_bar_inner + self.header_bar_inner .as_widget() - .a11y_nodes(c_layout, c_state, p); - ret + .a11y_nodes(c_layout, c_state, p) } } diff --git a/src/widget/menu/menu_bar.rs b/src/widget/menu/menu_bar.rs index 30c802c1..bbbb4a2b 100644 --- a/src/widget/menu/menu_bar.rs +++ b/src/widget/menu/menu_bar.rs @@ -97,7 +97,7 @@ impl Default for MenuBarStateInner { } } -pub(crate) fn menu_roots_children(menu_roots: &Vec>) -> Vec +pub(crate) fn menu_roots_children(menu_roots: &[MenuTree]) -> Vec where Message: Clone + 'static, { @@ -126,7 +126,7 @@ where } #[allow(invalid_reference_casting)] -pub(crate) fn menu_roots_diff(menu_roots: &mut Vec>, tree: &mut Tree) +pub(crate) fn menu_roots_diff(menu_roots: &mut [MenuTree], tree: &mut Tree) where Message: Clone + 'static, { @@ -381,7 +381,7 @@ where let surface_action = self.on_surface_action.as_ref().unwrap(); let old_active_root = my_state .inner - .with_data(|state| state.active_root.get(0).copied()); + .with_data(|state| state.active_root.first().copied()); // if position is not on menu bar button skip. let hovered_root = layout diff --git a/src/widget/menu/menu_inner.rs b/src/widget/menu/menu_inner.rs index 6c694de7..18f9940d 100644 --- a/src/widget/menu/menu_inner.rs +++ b/src/widget/menu/menu_inner.rs @@ -435,7 +435,7 @@ impl MenuState { pub(crate) struct Menu<'b, Message: std::clone::Clone> { pub(crate) tree: MenuBarState, // Flattened menu tree - pub(crate) menu_roots: Cow<'b, Vec>>, + pub(crate) menu_roots: Cow<'b, [MenuTree]>, pub(crate) bounds_expand: u16, /// Allows menu overlay items to overlap the parent pub(crate) menu_overlays_parent: bool, @@ -740,7 +740,7 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> { let styling = theme.appearance(&self.style); let roots = active_root.iter().skip(1).fold( &self.menu_roots[active_root[0]].children, - |mt, next_active_root| (&mt[*next_active_root].children), + |mt, next_active_root| &mt[*next_active_root].children, ); let indices = state.get_trimmed_indices(self.depth).collect::>(); state.menu_states[if self.is_overlay { 0 } else { self.depth }..=if self.is_overlay { diff --git a/src/widget/menu/menu_tree.rs b/src/widget/menu/menu_tree.rs index 67f999f7..e63e523b 100644 --- a/src/widget/menu/menu_tree.rs +++ b/src/widget/menu/menu_tree.rs @@ -119,7 +119,7 @@ impl MenuTree { }); mt.children.iter().for_each(|c| { - rec(&c, flat); + rec(c, flat); }); } diff --git a/src/widget/nav_bar.rs b/src/widget/nav_bar.rs index 1ae4005d..140385bc 100644 --- a/src/widget/nav_bar.rs +++ b/src/widget/nav_bar.rs @@ -26,7 +26,7 @@ pub type Model = segmented_button::SingleSelectModel; pub fn nav_bar( model: &segmented_button::SingleSelectModel, on_activate: fn(segmented_button::Entity) -> Message, -) -> NavBar { +) -> NavBar<'_, Message> { NavBar { segmented_button: segmented_button::vertical(model).on_activate(on_activate), } @@ -41,7 +41,7 @@ pub fn nav_bar_dnd( on_dnd_leave: impl Fn(segmented_button::Entity) -> Message + 'static, on_dnd_drop: impl Fn(segmented_button::Entity, Option, DndAction) -> Message + 'static, id: DragId, -) -> NavBar +) -> NavBar<'_, Message> where Message: Clone + 'static, { diff --git a/src/widget/responsive_menu_bar.rs b/src/widget/responsive_menu_bar.rs index 3c9151e7..5f855260 100644 --- a/src/widget/responsive_menu_bar.rs +++ b/src/widget/responsive_menu_bar.rs @@ -132,7 +132,7 @@ impl ResponsiveMenuBar { key_binds, trees .into_iter() - .map(|mt| menu::Item::Folder(mt.0, mt.1.into())) + .map(|mt| menu::Item::Folder(mt.0, mt.1)) .collect(), ) .into_iter() diff --git a/src/widget/segmented_button/horizontal.rs b/src/widget/segmented_button/horizontal.rs index 966f3a7c..3e46dd5e 100644 --- a/src/widget/segmented_button/horizontal.rs +++ b/src/widget/segmented_button/horizontal.rs @@ -23,7 +23,7 @@ pub struct Horizontal; /// For details on the model, see the [`segmented_button`](super) module for more details. pub fn horizontal( model: &Model, -) -> SegmentedButton +) -> SegmentedButton<'_, Horizontal, SelectionMode, Message> where Model: Selectable, { diff --git a/src/widget/segmented_button/model/mod.rs b/src/widget/segmented_button/model/mod.rs index 83a1702d..6b5a8a64 100644 --- a/src/widget/segmented_button/model/mod.rs +++ b/src/widget/segmented_button/model/mod.rs @@ -292,7 +292,7 @@ where /// ``` #[must_use] #[inline] - pub fn insert(&mut self) -> EntityMut { + pub fn insert(&mut self) -> EntityMut<'_, SelectionMode> { let id = self.items.insert(Settings::default()); self.order.push_back(id); EntityMut { model: self, id } @@ -447,7 +447,11 @@ where /// println!("{:?} had text {}", id, old_text) /// } /// ``` - pub fn text_set(&mut self, id: Entity, text: impl Into>) -> Option> { + pub fn text_set( + &mut self, + id: Entity, + text: impl Into>, + ) -> Option> { if !self.contains_item(id) { return None; } diff --git a/src/widget/segmented_button/vertical.rs b/src/widget/segmented_button/vertical.rs index ce9f50fe..7963e9c8 100644 --- a/src/widget/segmented_button/vertical.rs +++ b/src/widget/segmented_button/vertical.rs @@ -22,7 +22,7 @@ pub type VerticalSegmentedButton<'a, SelectionMode, Message> = /// For details on the model, see the [`segmented_button`](super) module for more details. pub fn vertical( model: &Model, -) -> SegmentedButton +) -> SegmentedButton<'_, Vertical, SelectionMode, Message> where Model: Selectable, SelectionMode: Default, diff --git a/src/widget/segmented_button/widget.rs b/src/widget/segmented_button/widget.rs index 0fd8dcd6..3cbe12f9 100644 --- a/src/widget/segmented_button/widget.rs +++ b/src/widget/segmented_button/widget.rs @@ -263,7 +263,7 @@ where /// Check if an item is enabled. fn is_enabled(&self, key: Entity) -> bool { - self.model.items.get(key).map_or(false, |item| item.enabled) + self.model.items.get(key).is_some_and(|item| item.enabled) } /// Handle the dnd drop event. @@ -987,7 +987,7 @@ where let current = Instant::now(); // Permit successive scroll wheel events only after a given delay. - if state.wheel_timestamp.map_or(true, |previous| { + if state.wheel_timestamp.is_none_or(|previous| { current.duration_since(previous) > Duration::from_millis(250) }) { state.wheel_timestamp = Some(current); @@ -1607,23 +1607,16 @@ where let state = tree.state.downcast_ref::(); let menu_state = state.menu_state.clone(); - let Some(entity) = state.show_context else { - return None; - }; + let entity = state.show_context?; - let bounds = self - .variant_bounds(state, layout.bounds()) - .find_map(|item| match item { - ItemBounds::Button(e, bounds) if e == entity => Some(bounds), - _ => None, - }); - let Some(mut bounds) = bounds else { - return None; - }; + let mut bounds = + self.variant_bounds(state, layout.bounds()) + .find_map(|item| match item { + ItemBounds::Button(e, bounds) if e == entity => Some(bounds), + _ => None, + })?; - let Some(context_menu) = self.context_menu.as_mut() else { - return None; - }; + let context_menu = self.context_menu.as_mut()?; if !menu_state.inner.with_data(|data| data.open) { // If the menu is not open, we don't need to show it. @@ -1777,9 +1770,8 @@ impl LocalState { impl operation::Focusable for LocalState { fn is_focused(&self) -> bool { - self.focused.map_or(false, |f| { - f.updated_at == LAST_FOCUS_UPDATE.with(|f| f.get()) - }) + self.focused + .is_some_and(|f| f.updated_at == LAST_FOCUS_UPDATE.with(|f| f.get())) } fn focus(&mut self) { diff --git a/src/widget/segmented_control.rs b/src/widget/segmented_control.rs index 0c213b2c..046956c7 100644 --- a/src/widget/segmented_control.rs +++ b/src/widget/segmented_control.rs @@ -16,7 +16,7 @@ use super::segmented_button::{ /// For details on the model, see the [`segmented_button`] module for more details. pub fn horizontal( model: &Model, -) -> HorizontalSegmentedButton +) -> HorizontalSegmentedButton<'_, SelectionMode, Message> where Model: Selectable, { @@ -39,7 +39,7 @@ where /// For details on the model, see the [`segmented_button`] module for more details. pub fn vertical( model: &Model, -) -> VerticalSegmentedButton +) -> VerticalSegmentedButton<'_, SelectionMode, Message> where Model: Selectable, SelectionMode: Default, diff --git a/src/widget/settings/item.rs b/src/widget/settings/item.rs index a8c38a0d..d62bbc99 100644 --- a/src/widget/settings/item.rs +++ b/src/widget/settings/item.rs @@ -131,7 +131,7 @@ impl<'a, Message: 'static> Item<'a, Message> { contents.push(text(self.title).width(Length::Fill).into()); } - contents.push(widget.into()); + contents.push(widget); contents } diff --git a/src/widget/tab_bar.rs b/src/widget/tab_bar.rs index 4f4c6149..a08128b4 100644 --- a/src/widget/tab_bar.rs +++ b/src/widget/tab_bar.rs @@ -16,7 +16,7 @@ use super::segmented_button::{ /// For details on the model, see the [`segmented_button`] module for more details. pub fn horizontal( model: &Model, -) -> HorizontalSegmentedButton +) -> HorizontalSegmentedButton<'_, SelectionMode, Message> where Model: Selectable, { @@ -37,7 +37,7 @@ where /// For details on the model, see the [`segmented_button`] module for more details. pub fn vertical( model: &Model, -) -> VerticalSegmentedButton +) -> VerticalSegmentedButton<'_, SelectionMode, Message> where Model: Selectable, SelectionMode: Default, diff --git a/src/widget/table/model/mod.rs b/src/widget/table/model/mod.rs index f664e438..d6250eaf 100644 --- a/src/widget/table/model/mod.rs +++ b/src/widget/table/model/mod.rs @@ -221,7 +221,7 @@ where /// let id = model.insert().text("Item A").icon("custom-icon").id(); /// ``` #[must_use] - pub fn insert(&mut self, item: Item) -> EntityMut { + pub fn insert(&mut self, item: Item) -> EntityMut<'_, SelectionMode, Item, Category> { let id = self.items.insert(item); self.order.push_back(id); EntityMut { model: self, id } @@ -244,7 +244,7 @@ where /// ``` #[must_use] pub fn is_enabled(&self, id: Entity) -> bool { - self.active.get(id).map_or(false, |e| *e) + self.active.get(id).is_some_and(|e| *e) } /// Iterates across items in the model in the order that they are displayed. @@ -288,9 +288,7 @@ where /// } /// ``` pub fn position_set(&mut self, id: Entity, position: u16) -> Option { - let Some(index) = self.position(id) else { - return None; - }; + let index = self.position(id)?; self.order.remove(index as usize); diff --git a/src/widget/table/widget/compact.rs b/src/widget/table/widget/compact.rs index 47864f6d..7cda2dfb 100644 --- a/src/widget/table/widget/compact.rs +++ b/src/widget/table/widget/compact.rs @@ -63,7 +63,7 @@ where .map(|entity| { let item = val.model.item(entity).unwrap(); let selected = val.model.is_active(entity); - let context_menu = (val.item_context_builder)(&item); + let context_menu = (val.item_context_builder)(item); widget::column() .spacing(val.item_spacing) @@ -89,14 +89,13 @@ where .categories .iter() .skip_while(|cat| **cat != Category::default()) - .map(|category| { - vec![ + .flat_map(|category| { + [ widget::text::caption(item.get_text(*category)) .apply(Element::from), widget::text::caption("-").apply(Element::from), ] }) - .flatten() .collect::>>(); elements.pop(); elements @@ -201,7 +200,7 @@ where divider_padding: Padding::from(0).left(space_xxxs).right(space_xxxs), - item_padding: Padding::from(space_xxs).into(), + item_padding: Padding::from(space_xxs), item_spacing: 0, icon_size: 48, diff --git a/src/widget/table/widget/standard.rs b/src/widget/table/widget/standard.rs index eb9ba7a4..3ee1ac4a 100644 --- a/src/widget/table/widget/standard.rs +++ b/src/widget/table/widget/standard.rs @@ -139,13 +139,13 @@ where } else { val.model .iter() - .map(move |entity| { + .flat_map(move |entity| { let item = val.model.item(entity).unwrap(); let categories = &val.model.categories; let selected = val.model.is_active(entity); - let item_context = (val.item_context_builder)(&item); + let item_context = (val.item_context_builder)(item); - vec![ + [ divider::horizontal::default() .apply(container) .padding(val.divider_padding) @@ -233,13 +233,11 @@ where .apply(Element::from), ] }) - .flatten() .collect::>>() }; - vec![vec![header_row], items_full] - .into_iter() - .flatten() - .collect::>>() + let mut elements = items_full; + elements.insert(0, header_row); + elements .apply(widget::column::with_children) .width(val.width) .height(val.height) @@ -272,7 +270,7 @@ where width: Length::Fill, height: Length::Shrink, - item_padding: Padding::from(space_xxs).into(), + item_padding: Padding::from(space_xxs), item_spacing: 0, icon_spacing: space_xxxs, icon_size: 24, diff --git a/src/widget/text_input/input.rs b/src/widget/text_input/input.rs index 12e8e7ce..ab38a718 100644 --- a/src/widget/text_input/input.rs +++ b/src/widget/text_input/input.rs @@ -546,7 +546,6 @@ where } /// Get the layout node of the actual text input - fn text_layout<'b>(&'a self, layout: Layout<'b>) -> Layout<'b> { if self.dnd_icon { layout @@ -1389,8 +1388,8 @@ pub fn update<'a, Message: Clone + 'static>( if let Some(cursor_position) = click_position { // Check if the edit button was clicked. - if state.dragging_state == None - && edit_button_layout.map_or(false, |l| cursor.is_over(l.bounds())) + if state.dragging_state.is_none() + && edit_button_layout.is_some_and(|l| cursor.is_over(l.bounds())) { if is_editable_variant { state.is_read_only = !state.is_read_only; @@ -2277,7 +2276,7 @@ pub fn draw<'a, Message>( let (cursor, offset) = if let Some(focus) = state.is_focused.filter(|f| f.focused).or_else(|| { let now = Instant::now(); - handling_dnd_offer.then(|| Focus { + handling_dnd_offer.then_some(Focus { needs_update: false, updated_at: now, now, diff --git a/src/widget/text_input/value.rs b/src/widget/text_input/value.rs index 60647db3..900aac0f 100644 --- a/src/widget/text_input/value.rs +++ b/src/widget/text_input/value.rs @@ -129,9 +129,7 @@ impl Value { #[must_use] pub fn secure(&self) -> Self { Self { - graphemes: std::iter::repeat(String::from("•")) - .take(self.graphemes.len()) - .collect(), + graphemes: std::iter::repeat_n(String::from("•"), self.graphemes.len()).collect(), } } }