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

@ -23,7 +23,7 @@ pub struct Horizontal;
/// For details on the model, see the [`segmented_button`](super) module for more details.
pub fn horizontal<SelectionMode: Default, Message>(
model: &Model<SelectionMode>,
) -> SegmentedButton<Horizontal, SelectionMode, Message>
) -> SegmentedButton<'_, Horizontal, SelectionMode, Message>
where
Model<SelectionMode>: Selectable,
{

View file

@ -292,7 +292,7 @@ where
/// ```
#[must_use]
#[inline]
pub fn insert(&mut self) -> EntityMut<SelectionMode> {
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<Cow<'static, str>>) -> Option<Cow<str>> {
pub fn text_set(
&mut self,
id: Entity,
text: impl Into<Cow<'static, str>>,
) -> Option<Cow<'_, str>> {
if !self.contains_item(id) {
return None;
}

View file

@ -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<SelectionMode, Message>(
model: &Model<SelectionMode>,
) -> SegmentedButton<Vertical, SelectionMode, Message>
) -> SegmentedButton<'_, Vertical, SelectionMode, Message>
where
Model<SelectionMode>: Selectable,
SelectionMode: Default,

View file

@ -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::<LocalState>();
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) {