chore: apply clippy suggestions

This commit is contained in:
Cheong Lau 2025-10-05 12:27:32 +10:00 committed by Michael Murphy
parent 34f55d6720
commit a27bb5e05d
34 changed files with 116 additions and 146 deletions

View file

@ -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<SelectionMode, Item, Category> {
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<usize> {
let Some(index) = self.position(id) else {
return None;
};
let index = self.position(id)?;
self.order.remove(index as usize);

View file

@ -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::<Vec<Element<'static, Message>>>();
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,

View file

@ -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<Element<'a, Message>>>()
};
vec![vec![header_row], items_full]
.into_iter()
.flatten()
.collect::<Vec<Element<'a, Message>>>()
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,