diff --git a/masonry/src/box_constraints.rs b/masonry/src/box_constraints.rs index fd96d0fe1..db62ee502 100644 --- a/masonry/src/box_constraints.rs +++ b/masonry/src/box_constraints.rs @@ -31,7 +31,7 @@ impl BoxConstraints { /// An unbounded box constraints object. /// /// Can be satisfied by any nonnegative size. - pub const UNBOUNDED: BoxConstraints = BoxConstraints { + pub const UNBOUNDED: Self = Self { min: Size::ZERO, max: Size::new(f64::INFINITY, f64::INFINITY), }; @@ -44,8 +44,8 @@ impl BoxConstraints { /// so that the layout is aligned to integers. /// /// [rounded away from zero]: Size::expand - pub fn new(min: Size, max: Size) -> BoxConstraints { - BoxConstraints { + pub fn new(min: Size, max: Size) -> Self { + Self { min: min.expand(), max: max.expand(), } @@ -59,9 +59,9 @@ impl BoxConstraints { /// so that the layout is aligned to integers. /// /// [rounded away from zero]: Size::expand - pub fn tight(size: Size) -> BoxConstraints { + pub fn tight(size: Size) -> Self { let size = size.expand(); - BoxConstraints { + Self { min: size, max: size, } @@ -70,8 +70,8 @@ impl BoxConstraints { /// Create a "loose" version of the constraints. /// /// Make a version with zero minimum size, but the same maximum size. - pub fn loosen(&self) -> BoxConstraints { - BoxConstraints { + pub fn loosen(&self) -> Self { + Self { min: Size::ZERO, max: self.max, } @@ -152,7 +152,7 @@ impl BoxConstraints { /// so that the layout is aligned to integers. /// /// [rounded away from zero]: Size::expand - pub fn shrink(&self, diff: impl Into) -> BoxConstraints { + pub fn shrink(&self, diff: impl Into) -> Self { let diff = diff.into().expand(); let min = Size::new( (self.min().width - diff.width).max(0.), @@ -163,7 +163,7 @@ impl BoxConstraints { (self.max().height - diff.height).max(0.), ); - BoxConstraints::new(min, max) + Self::new(min, max) } /// Test whether these constraints contain the given `Size`. diff --git a/masonry/src/debug_logger.rs b/masonry/src/debug_logger.rs index 212b568b5..7b50564d3 100644 --- a/masonry/src/debug_logger.rs +++ b/masonry/src/debug_logger.rs @@ -38,7 +38,7 @@ pub struct DebugLogger { impl DebugLogger { pub fn new(activated: bool) -> Self { - let mut new_self = DebugLogger { + let mut new_self = Self { activated, layout_tree: Default::default(), widget_states: Default::default(), diff --git a/masonry/src/debug_values.rs b/masonry/src/debug_values.rs index 3146ab726..d5934a06c 100644 --- a/masonry/src/debug_values.rs +++ b/masonry/src/debug_values.rs @@ -76,49 +76,49 @@ pub struct Timeline { impl Display for Value { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Value::Empty => write!(f, ""), - Value::String(string) => write!(f, "{}", string), - Value::Bool(b) => write!(f, "{}", b), - Value::Rect(rect) => write!(f, "{:?}", rect), - Value::Id(id) => write!(f, "{}", id), - Value::LogId(_) => write!(f, ""), + Self::Empty => write!(f, ""), + Self::String(string) => write!(f, "{}", string), + Self::Bool(b) => write!(f, "{}", b), + Self::Rect(rect) => write!(f, "{:?}", rect), + Self::Id(id) => write!(f, "{}", id), + Self::LogId(_) => write!(f, ""), } } } impl From for Value { - fn from(value: String) -> Value { - Value::String(value) + fn from(value: String) -> Self { + Self::String(value) } } impl From for Value { - fn from(value: bool) -> Value { - Value::Bool(value) + fn from(value: bool) -> Self { + Self::Bool(value) } } impl From for Value { - fn from(value: Rect) -> Value { - Value::Rect(value) + fn from(value: Rect) -> Self { + Self::Rect(value) } } impl From for Value { - fn from(value: MyWidgetId) -> Value { - Value::Id(value) + fn from(value: MyWidgetId) -> Self { + Self::Id(value) } } impl From for Value { - fn from(value: LogId) -> Value { - Value::LogId(value) + fn from(value: LogId) -> Self { + Self::LogId(value) } } impl StateTree { pub fn new(name: impl Into, value: impl Into) -> Self { - StateTree { + Self { name: name.into(), value: value.into(), folded_by_default: false, diff --git a/masonry/src/event.rs b/masonry/src/event.rs index 29294f62c..d53b62200 100644 --- a/masonry/src/event.rs +++ b/masonry/src/event.rs @@ -67,8 +67,8 @@ fn button_bit(button: PointerButton) -> u8 { impl PointerButtons { /// Create a new empty set. #[inline] - pub fn new() -> PointerButtons { - PointerButtons(0) + pub fn new() -> Self { + Self(0) } /// Add the `button` to the set. @@ -97,12 +97,12 @@ impl PointerButtons { /// Returns `true` if all the `buttons` are in the set. #[inline] - pub fn contains_all(self, buttons: PointerButtons) -> bool { + pub fn contains_all(self, buttons: Self) -> bool { self.0 & buttons.0 == buttons.0 } /// Adds all the `buttons` to the set. - pub fn extend(&mut self, buttons: PointerButtons) { + pub fn extend(&mut self, buttons: Self) { self.0 |= buttons.0; } @@ -325,58 +325,58 @@ impl PointerEvent { focus: false, force: None, }; - PointerEvent::PointerLeave(pointer_state) + Self::PointerLeave(pointer_state) } pub fn pointer_state(&self) -> &PointerState { match self { - PointerEvent::PointerDown(_, state) - | PointerEvent::PointerUp(_, state) - | PointerEvent::PointerMove(state) - | PointerEvent::PointerEnter(state) - | PointerEvent::PointerLeave(state) - | PointerEvent::MouseWheel(_, state) - | PointerEvent::HoverFile(_, state) - | PointerEvent::DropFile(_, state) - | PointerEvent::HoverFileCancel(state) - | PointerEvent::Pinch(_, state) => state, + Self::PointerDown(_, state) + | Self::PointerUp(_, state) + | Self::PointerMove(state) + | Self::PointerEnter(state) + | Self::PointerLeave(state) + | Self::MouseWheel(_, state) + | Self::HoverFile(_, state) + | Self::DropFile(_, state) + | Self::HoverFileCancel(state) + | Self::Pinch(_, state) => state, } } pub fn position(&self) -> Option> { match self { - PointerEvent::PointerLeave(_) | PointerEvent::HoverFileCancel(_) => None, + Self::PointerLeave(_) | Self::HoverFileCancel(_) => None, _ => Some(self.pointer_state().position), } } pub fn short_name(&self) -> &'static str { match self { - PointerEvent::PointerDown(_, _) => "PointerDown", - PointerEvent::PointerUp(_, _) => "PointerUp", - PointerEvent::PointerMove(_) => "PointerMove", - PointerEvent::PointerEnter(_) => "PointerEnter", - PointerEvent::PointerLeave(_) => "PointerLeave", - PointerEvent::MouseWheel(_, _) => "MouseWheel", - PointerEvent::HoverFile(_, _) => "HoverFile", - PointerEvent::DropFile(_, _) => "DropFile", - PointerEvent::HoverFileCancel(_) => "HoverFileCancel", - PointerEvent::Pinch(_, _) => "Pinch", + Self::PointerDown(_, _) => "PointerDown", + Self::PointerUp(_, _) => "PointerUp", + Self::PointerMove(_) => "PointerMove", + Self::PointerEnter(_) => "PointerEnter", + Self::PointerLeave(_) => "PointerLeave", + Self::MouseWheel(_, _) => "MouseWheel", + Self::HoverFile(_, _) => "HoverFile", + Self::DropFile(_, _) => "DropFile", + Self::HoverFileCancel(_) => "HoverFileCancel", + Self::Pinch(_, _) => "Pinch", } } pub fn is_high_density(&self) -> bool { match self { - PointerEvent::PointerDown(_, _) => false, - PointerEvent::PointerUp(_, _) => false, - PointerEvent::PointerMove(_) => true, - PointerEvent::PointerEnter(_) => false, - PointerEvent::PointerLeave(_) => false, - PointerEvent::MouseWheel(_, _) => true, - PointerEvent::HoverFile(_, _) => true, - PointerEvent::DropFile(_, _) => false, - PointerEvent::HoverFileCancel(_) => false, - PointerEvent::Pinch(_, _) => true, + Self::PointerDown(_, _) => false, + Self::PointerUp(_, _) => false, + Self::PointerMove(_) => true, + Self::PointerEnter(_) => false, + Self::PointerLeave(_) => false, + Self::MouseWheel(_, _) => true, + Self::HoverFile(_, _) => true, + Self::DropFile(_, _) => false, + Self::HoverFileCancel(_) => false, + Self::Pinch(_, _) => true, } } } @@ -384,25 +384,25 @@ impl PointerEvent { impl TextEvent { pub fn short_name(&self) -> &'static str { match self { - TextEvent::KeyboardKey(KeyEvent { repeat: true, .. }, _) => "KeyboardKey (repeat)", - TextEvent::KeyboardKey(_, _) => "KeyboardKey", - TextEvent::Ime(Ime::Disabled) => "Ime::Disabled", - TextEvent::Ime(Ime::Enabled) => "Ime::Enabled", - TextEvent::Ime(Ime::Commit(_)) => "Ime::Commit", - TextEvent::Ime(Ime::Preedit(s, _)) if s.is_empty() => "Ime::Preedit(\"\")", - TextEvent::Ime(Ime::Preedit(_, _)) => "Ime::Preedit", - TextEvent::ModifierChange(_) => "ModifierChange", - TextEvent::FocusChange(_) => "FocusChange", + Self::KeyboardKey(KeyEvent { repeat: true, .. }, _) => "KeyboardKey (repeat)", + Self::KeyboardKey(_, _) => "KeyboardKey", + Self::Ime(Ime::Disabled) => "Ime::Disabled", + Self::Ime(Ime::Enabled) => "Ime::Enabled", + Self::Ime(Ime::Commit(_)) => "Ime::Commit", + Self::Ime(Ime::Preedit(s, _)) if s.is_empty() => "Ime::Preedit(\"\")", + Self::Ime(Ime::Preedit(_, _)) => "Ime::Preedit", + Self::ModifierChange(_) => "ModifierChange", + Self::FocusChange(_) => "FocusChange", } } pub fn is_high_density(&self) -> bool { match self { - TextEvent::KeyboardKey(_, _) => false, - TextEvent::Ime(_) => false, + Self::KeyboardKey(_, _) => false, + Self::Ime(_) => false, // Basically every mouse click/scroll event seems to produce a modifier change event. - TextEvent::ModifierChange(_) => true, - TextEvent::FocusChange(_) => false, + Self::ModifierChange(_) => true, + Self::FocusChange(_) => false, } } } @@ -451,7 +451,7 @@ impl PointerState { // It would be a lot better if winit could just make this constructor safe. let device_id = unsafe { DeviceId::dummy() }; - PointerState { + Self { physical_position: PhysicalPosition::new(0.0, 0.0), position: LogicalPosition::new(0.0, 0.0), buttons: Default::default(), @@ -469,13 +469,13 @@ impl Update { /// Essentially returns the enum variant name. pub fn short_name(&self) -> &str { match self { - Update::WidgetAdded => "WidgetAdded", - Update::DisabledChanged(_) => "DisabledChanged", - Update::StashedChanged(_) => "StashedChanged", - Update::RequestPanToChild(_) => "RequestPanToChild", - Update::HoveredChanged(_) => "HoveredChanged", - Update::FocusChanged(_) => "FocusChanged", - Update::ChildFocusChanged(_) => "ChildFocusChanged", + Self::WidgetAdded => "WidgetAdded", + Self::DisabledChanged(_) => "DisabledChanged", + Self::StashedChanged(_) => "StashedChanged", + Self::RequestPanToChild(_) => "RequestPanToChild", + Self::HoveredChanged(_) => "HoveredChanged", + Self::FocusChanged(_) => "FocusChanged", + Self::ChildFocusChanged(_) => "ChildFocusChanged", } } } diff --git a/masonry/src/event_loop_runner.rs b/masonry/src/event_loop_runner.rs index dda6a5636..b8c6d68b5 100644 --- a/masonry/src/event_loop_runner.rs +++ b/masonry/src/event_loop_runner.rs @@ -42,14 +42,14 @@ impl From for MasonryUserEvent { impl From for PointerButton { fn from(button: WinitMouseButton) -> Self { match button { - WinitMouseButton::Left => PointerButton::Primary, - WinitMouseButton::Right => PointerButton::Secondary, - WinitMouseButton::Middle => PointerButton::Auxiliary, - WinitMouseButton::Back => PointerButton::X1, - WinitMouseButton::Forward => PointerButton::X2, + WinitMouseButton::Left => Self::Primary, + WinitMouseButton::Right => Self::Secondary, + WinitMouseButton::Middle => Self::Auxiliary, + WinitMouseButton::Back => Self::X1, + WinitMouseButton::Forward => Self::X2, WinitMouseButton::Other(other) => { warn!("Got winit MouseButton::Other({other}) which is not yet fully supported."); - PointerButton::Other + Self::Other } } } diff --git a/masonry/src/lib.rs b/masonry/src/lib.rs index a948bb28d..454c5ef28 100644 --- a/masonry/src/lib.rs +++ b/masonry/src/lib.rs @@ -124,7 +124,6 @@ #![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")] #![expect(clippy::return_self_not_must_use, reason = "Deferred: Noisy")] #![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")] -#![expect(clippy::use_self, reason = "Deferred: Noisy")] // https://github.com/rust-lang/rust/pull/130025 #![allow(missing_docs, reason = "We have many as-yet undocumented items")] #![expect(unreachable_pub, reason = "Potentially controversial code style")] diff --git a/masonry/src/paint_scene_helpers.rs b/masonry/src/paint_scene_helpers.rs index 014b1ed07..68415782d 100644 --- a/masonry/src/paint_scene_helpers.rs +++ b/masonry/src/paint_scene_helpers.rs @@ -33,30 +33,30 @@ pub fn stroke<'b>( #[allow(unused)] impl UnitPoint { /// `(0.0, 0.0)` - pub const TOP_LEFT: UnitPoint = UnitPoint::new(0.0, 0.0); + pub const TOP_LEFT: Self = Self::new(0.0, 0.0); /// `(0.5, 0.0)` - pub const TOP: UnitPoint = UnitPoint::new(0.5, 0.0); + pub const TOP: Self = Self::new(0.5, 0.0); /// `(1.0, 0.0)` - pub const TOP_RIGHT: UnitPoint = UnitPoint::new(1.0, 0.0); + pub const TOP_RIGHT: Self = Self::new(1.0, 0.0); /// `(0.0, 0.5)` - pub const LEFT: UnitPoint = UnitPoint::new(0.0, 0.5); + pub const LEFT: Self = Self::new(0.0, 0.5); /// `(0.5, 0.5)` - pub const CENTER: UnitPoint = UnitPoint::new(0.5, 0.5); + pub const CENTER: Self = Self::new(0.5, 0.5); /// `(1.0, 0.5)` - pub const RIGHT: UnitPoint = UnitPoint::new(1.0, 0.5); + pub const RIGHT: Self = Self::new(1.0, 0.5); /// `(0.0, 1.0)` - pub const BOTTOM_LEFT: UnitPoint = UnitPoint::new(0.0, 1.0); + pub const BOTTOM_LEFT: Self = Self::new(0.0, 1.0); /// `(0.5, 1.0)` - pub const BOTTOM: UnitPoint = UnitPoint::new(0.5, 1.0); + pub const BOTTOM: Self = Self::new(0.5, 1.0); /// `(1.0, 1.0)` - pub const BOTTOM_RIGHT: UnitPoint = UnitPoint::new(1.0, 1.0); + pub const BOTTOM_RIGHT: Self = Self::new(1.0, 1.0); /// Create a new `UnitPoint`. /// /// The `u` and `v` coordinates describe the point, with (0.0, 0.0) being /// the top-left, and (1.0, 1.0) being the bottom-right. - pub const fn new(u: f64, v: f64) -> UnitPoint { - UnitPoint { u, v } + pub const fn new(u: f64, v: f64) -> Self { + Self { u, v } } /// Given a rectangle, resolve the point within the rectangle. diff --git a/masonry/src/render_root.rs b/masonry/src/render_root.rs index d52df7c76..d6ddb0aae 100644 --- a/masonry/src/render_root.rs +++ b/masonry/src/render_root.rs @@ -150,7 +150,7 @@ impl RenderRoot { test_font, }: RenderRootOptions, ) -> Self { - let mut root = RenderRoot { + let mut root = Self { root: WidgetPod::new(root_widget).boxed(), size_policy, size: PhysicalSize::new(0, 0), @@ -623,7 +623,7 @@ impl RenderRootState { impl RenderRootSignal { pub(crate) fn new_ime_moved_signal(area: Rect) -> Self { - RenderRootSignal::ImeMoved( + Self::ImeMoved( LogicalPosition { x: area.origin().x, y: area.origin().y, diff --git a/masonry/src/testing/harness.rs b/masonry/src/testing/harness.rs index 938df768e..0888dc4bd 100644 --- a/masonry/src/testing/harness.rs +++ b/masonry/src/testing/harness.rs @@ -182,7 +182,7 @@ impl TestHarness { )); let data = ROBOTO.to_vec(); - let mut harness = TestHarness { + let mut harness = Self { render_root: RenderRoot::new( root_widget, RenderRootOptions { diff --git a/masonry/src/testing/helper_widgets.rs b/masonry/src/testing/helper_widgets.rs index cf69eb506..d6afe054b 100644 --- a/masonry/src/testing/helper_widgets.rs +++ b/masonry/src/testing/helper_widgets.rs @@ -143,7 +143,7 @@ impl ModularWidget { /// By default none of its methods do anything, and its layout method returns /// a static 100x100 size. pub fn new(state: S) -> Self { - ModularWidget { + Self { state, accepts_pointer_interaction: true, accepts_focus: false, @@ -321,7 +321,7 @@ impl Widget for ModularWidget { } fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { - let ModularWidget { + let Self { ref mut state, ref mut layout, .. @@ -423,7 +423,7 @@ impl ReplaceChild { pub fn new(child: impl Widget, f: impl Fn() -> W + 'static) -> Self { let child = WidgetPod::new(child).boxed(); let replacer = Box::new(move || WidgetPod::new(f()).boxed()); - ReplaceChild { child, replacer } + Self { child, replacer } } } diff --git a/masonry/src/util.rs b/masonry/src/util.rs index e11411a6a..bf56513e6 100644 --- a/masonry/src/util.rs +++ b/masonry/src/util.rs @@ -45,17 +45,17 @@ pub enum Handled { impl Handled { /// Has the event been handled yet? pub fn is_handled(self) -> bool { - self == Handled::Yes + self == Self::Yes } } impl From for Handled { /// Returns `Handled::Yes` if `handled` is true, and `Handled::No` otherwise. - fn from(handled: bool) -> Handled { + fn from(handled: bool) -> Self { if handled { - Handled::Yes + Self::Yes } else { - Handled::No + Self::No } } } diff --git a/masonry/src/widget/align.rs b/masonry/src/widget/align.rs index 4c91fbfe7..66e081d78 100644 --- a/masonry/src/widget/align.rs +++ b/masonry/src/widget/align.rs @@ -38,8 +38,8 @@ impl Align { /// Note that the `align` parameter is specified as a `UnitPoint` in /// terms of left and right. This is inadequate for bidi-aware layout /// and thus the API will change when Masonry gains bidi capability. - pub fn new(align: UnitPoint, child: impl Widget + 'static) -> Align { - Align { + pub fn new(align: UnitPoint, child: impl Widget + 'static) -> Self { + Self { align, child: WidgetPod::new(child).boxed(), width_factor: None, @@ -48,23 +48,23 @@ impl Align { } /// Create centered widget. - pub fn centered(child: impl Widget + 'static) -> Align { - Align::new(UnitPoint::CENTER, child) + pub fn centered(child: impl Widget + 'static) -> Self { + Self::new(UnitPoint::CENTER, child) } /// Create right-aligned widget. - pub fn right(child: impl Widget + 'static) -> Align { - Align::new(UnitPoint::RIGHT, child) + pub fn right(child: impl Widget + 'static) -> Self { + Self::new(UnitPoint::RIGHT, child) } /// Create left-aligned widget. - pub fn left(child: impl Widget + 'static) -> Align { - Align::new(UnitPoint::LEFT, child) + pub fn left(child: impl Widget + 'static) -> Self { + Self::new(UnitPoint::LEFT, child) } /// Align only in the horizontal axis, keeping the child's size in the vertical. - pub fn horizontal(align: UnitPoint, child: impl Widget + 'static) -> Align { - Align { + pub fn horizontal(align: UnitPoint, child: impl Widget + 'static) -> Self { + Self { align, child: WidgetPod::new(child).boxed(), width_factor: None, @@ -73,8 +73,8 @@ impl Align { } /// Align only in the vertical axis, keeping the child's size in the horizontal. - pub fn vertical(align: UnitPoint, child: impl Widget + 'static) -> Align { - Align { + pub fn vertical(align: UnitPoint, child: impl Widget + 'static) -> Self { + Self { align, child: WidgetPod::new(child).boxed(), width_factor: Some(1.0), diff --git a/masonry/src/widget/button.rs b/masonry/src/widget/button.rs index 551727e09..322109053 100644 --- a/masonry/src/widget/button.rs +++ b/masonry/src/widget/button.rs @@ -41,8 +41,8 @@ impl Button { /// /// let button = Button::new("Increment"); /// ``` - pub fn new(text: impl Into) -> Button { - Button::from_label(Label::new(text)) + pub fn new(text: impl Into) -> Self { + Self::from_label(Label::new(text)) } /// Create a new button with the provided [`Label`]. @@ -56,8 +56,8 @@ impl Button { /// let label = Label::new("Increment").with_brush(Color::rgb(0.5, 0.5, 0.5)); /// let button = Button::from_label(label); /// ``` - pub fn from_label(label: Label) -> Button { - Button { + pub fn from_label(label: Label) -> Self { + Self { label: WidgetPod::new(label), } } diff --git a/masonry/src/widget/checkbox.rs b/masonry/src/widget/checkbox.rs index b8e10a40d..57bd3d903 100644 --- a/masonry/src/widget/checkbox.rs +++ b/masonry/src/widget/checkbox.rs @@ -26,16 +26,16 @@ pub struct Checkbox { impl Checkbox { /// Create a new `Checkbox` with a text label. - pub fn new(checked: bool, text: impl Into) -> Checkbox { - Checkbox { + pub fn new(checked: bool, text: impl Into) -> Self { + Self { checked, label: WidgetPod::new(Label::new(text)), } } /// Create a new `Checkbox` with the given label. - pub fn from_label(checked: bool, label: Label) -> Checkbox { - Checkbox { + pub fn from_label(checked: bool, label: Label) -> Self { + Self { checked, label: WidgetPod::new(label), } @@ -54,7 +54,7 @@ impl Checkbox { /// /// We enforce this to be an `ArcStr` to make the allocation explicit. pub fn set_text(this: &mut WidgetMut<'_, Self>, new_text: ArcStr) { - Label::set_text(&mut Checkbox::label_mut(this), new_text); + Label::set_text(&mut Self::label_mut(this), new_text); } pub fn label_mut<'t>(this: &'t mut WidgetMut<'_, Self>) -> WidgetMut<'t, Label> { diff --git a/masonry/src/widget/flex.rs b/masonry/src/widget/flex.rs index 98e463505..77a7dbaa4 100644 --- a/masonry/src/widget/flex.rs +++ b/masonry/src/widget/flex.rs @@ -120,7 +120,7 @@ enum Child { impl Flex { /// Create a new Flex oriented along the provided axis. pub fn for_axis(axis: Axis) -> Self { - Flex { + Self { direction: axis, children: Vec::new(), cross_alignment: CrossAxisAlignment::Center, @@ -414,7 +414,7 @@ impl Flex { /// a row or column, as well as theme settings. pub fn add_default_spacer(this: &mut WidgetMut<'_, Self>) { let key = axis_default_spacer(this.widget.direction); - Flex::add_spacer(this, key); + Self::add_spacer(this, key); this.ctx.request_layout(); } @@ -631,18 +631,18 @@ impl Flex { // --- MARK: OTHER IMPLS--- impl Axis { /// Get the axis perpendicular to this one. - pub fn cross(self) -> Axis { + pub fn cross(self) -> Self { match self { - Axis::Horizontal => Axis::Vertical, - Axis::Vertical => Axis::Horizontal, + Self::Horizontal => Self::Vertical, + Self::Vertical => Self::Horizontal, } } /// Extract from the argument the magnitude along this axis pub fn major(self, size: Size) -> f64 { match self { - Axis::Horizontal => size.width, - Axis::Vertical => size.height, + Self::Horizontal => size.width, + Self::Vertical => size.height, } } @@ -654,8 +654,8 @@ impl Axis { /// Extract the extent of the argument in this axis as a pair. pub fn major_span(self, rect: Rect) -> (f64, f64) { match self { - Axis::Horizontal => (rect.x0, rect.x1), - Axis::Vertical => (rect.y0, rect.y1), + Self::Horizontal => (rect.x0, rect.x1), + Self::Vertical => (rect.y0, rect.y1), } } @@ -667,16 +667,16 @@ impl Axis { /// Extract the coordinate locating the argument with respect to this axis. pub fn major_pos(self, pos: Point) -> f64 { match self { - Axis::Horizontal => pos.x, - Axis::Vertical => pos.y, + Self::Horizontal => pos.x, + Self::Vertical => pos.y, } } /// Extract the coordinate locating the argument with respect to this axis. pub fn major_vec(self, vec: Vec2) -> f64 { match self { - Axis::Horizontal => vec.x, - Axis::Vertical => vec.y, + Self::Horizontal => vec.x, + Self::Vertical => vec.y, } } @@ -695,8 +695,8 @@ impl Axis { /// an (x, y) pair. pub fn pack(self, major: f64, minor: f64) -> (f64, f64) { match self { - Axis::Horizontal => (major, minor), - Axis::Vertical => (minor, major), + Self::Horizontal => (major, minor), + Self::Vertical => (minor, major), } } @@ -708,11 +708,11 @@ impl Axis { major: f64, ) -> BoxConstraints { match self { - Axis::Horizontal => BoxConstraints::new( + Self::Horizontal => BoxConstraints::new( Size::new(min_major, bc.min().height), Size::new(major, bc.max().height), ), - Axis::Vertical => BoxConstraints::new( + Self::Vertical => BoxConstraints::new( Size::new(bc.min().width, min_major), Size::new(bc.max().width, major), ), @@ -741,7 +741,7 @@ impl FlexParams { other => other, }; - FlexParams { + Self { flex, alignment: alignment.into(), } @@ -754,11 +754,11 @@ impl CrossAxisAlignment { /// this alignment. fn align(self, val: f64) -> f64 { match self { - CrossAxisAlignment::Start => 0.0, + Self::Start => 0.0, // in vertical layout, baseline is equivalent to center - CrossAxisAlignment::Center | CrossAxisAlignment::Baseline => (val / 2.0).round(), - CrossAxisAlignment::End => val, - CrossAxisAlignment::Fill => 0.0, + Self::Center | Self::Baseline => (val / 2.0).round(), + Self::End => val, + Self::Fill => 0.0, } } } @@ -768,7 +768,7 @@ impl Spacing { /// this returns an iterator of `f64` spacing, /// where the first element is the spacing before any children /// and all subsequent elements are the spacing after children. - fn new(alignment: MainAxisAlignment, extra: f64, n_children: usize) -> Spacing { + fn new(alignment: MainAxisAlignment, extra: f64, n_children: usize) -> Self { let extra = if extra.is_finite() { extra } else { 0. }; let equal_space = if n_children > 0 { match alignment { @@ -781,7 +781,7 @@ impl Spacing { } else { 0. }; - Spacing { + Self { alignment, extra, n_children, @@ -850,27 +850,27 @@ impl Iterator for Spacing { } impl From for FlexParams { - fn from(flex: f64) -> FlexParams { - FlexParams::new(flex, None) + fn from(flex: f64) -> Self { + Self::new(flex, None) } } impl From for FlexParams { - fn from(alignment: CrossAxisAlignment) -> FlexParams { - FlexParams::new(None, alignment) + fn from(alignment: CrossAxisAlignment) -> Self { + Self::new(None, alignment) } } impl Child { fn widget_mut(&mut self) -> Option<&mut WidgetPod>> { match self { - Child::Fixed { widget, .. } | Child::Flex { widget, .. } => Some(widget), + Self::Fixed { widget, .. } | Self::Flex { widget, .. } => Some(widget), _ => None, } } fn widget(&self) -> Option<&WidgetPod>> { match self { - Child::Fixed { widget, .. } | Child::Flex { widget, .. } => Some(widget), + Self::Fixed { widget, .. } | Self::Flex { widget, .. } => Some(widget), _ => None, } } diff --git a/masonry/src/widget/grid.rs b/masonry/src/widget/grid.rs index a752aca9c..d49dbb952 100644 --- a/masonry/src/widget/grid.rs +++ b/masonry/src/widget/grid.rs @@ -39,7 +39,7 @@ pub struct GridParams { // --- MARK: IMPL GRID --- impl Grid { pub fn with_dimensions(width: i32, height: i32) -> Self { - Grid { + Self { children: Vec::new(), grid_width: width, grid_height: height, @@ -109,7 +109,7 @@ fn new_grid_child(params: GridParams, widget: WidgetPod>) -> Chi // --- MARK: IMPL GRIDPARAMS --- impl GridParams { - pub fn new(mut x: i32, mut y: i32, mut width: i32, mut height: i32) -> GridParams { + pub fn new(mut x: i32, mut y: i32, mut width: i32, mut height: i32) -> Self { if x < 0 { debug_panic!("Grid x value should be a non-negative number; got {}", x); x = 0; @@ -132,7 +132,7 @@ impl GridParams { ); height = 1; } - GridParams { + Self { x, y, width, diff --git a/masonry/src/widget/image.rs b/masonry/src/widget/image.rs index adbcc8e96..80d66b080 100644 --- a/masonry/src/widget/image.rs +++ b/masonry/src/widget/image.rs @@ -38,7 +38,7 @@ impl Image { /// By default, the Image will scale to fit its box constraints ([`ObjectFit::Fill`]). #[inline] pub fn new(image_data: ImageBuf) -> Self { - Image { + Self { image_data, object_fit: ObjectFit::default(), } diff --git a/masonry/src/widget/mod.rs b/masonry/src/widget/mod.rs index b4cd5d89a..9d4a4ba90 100644 --- a/masonry/src/widget/mod.rs +++ b/masonry/src/widget/mod.rs @@ -93,22 +93,22 @@ impl ObjectFit { let raw_scaley = parent.height / fit_box.height; let (scalex, scaley) = match self { - ObjectFit::Contain => { + Self::Contain => { let scale = raw_scalex.min(raw_scaley); (scale, scale) } - ObjectFit::Cover => { + Self::Cover => { let scale = raw_scalex.max(raw_scaley); (scale, scale) } - ObjectFit::Fill => (raw_scalex, raw_scaley), - ObjectFit::FitHeight => (raw_scaley, raw_scaley), - ObjectFit::FitWidth => (raw_scalex, raw_scalex), - ObjectFit::ScaleDown => { + Self::Fill => (raw_scalex, raw_scaley), + Self::FitHeight => (raw_scaley, raw_scaley), + Self::FitWidth => (raw_scalex, raw_scalex), + Self::ScaleDown => { let scale = raw_scalex.min(raw_scaley).min(1.0); (scale, scale) } - ObjectFit::None => (1.0, 1.0), + Self::None => (1.0, 1.0), }; let origin_x = (parent.width - (fit_box.width * scalex)) / 2.0; diff --git a/masonry/src/widget/portal.rs b/masonry/src/widget/portal.rs index 6fa5169e0..1f741c991 100644 --- a/masonry/src/widget/portal.rs +++ b/masonry/src/widget/portal.rs @@ -46,7 +46,7 @@ impl Portal { } pub fn new_pod(child: WidgetPod) -> Self { - Portal { + Self { child, viewport_pos: Point::ORIGIN, constrain_horizontal: false, diff --git a/masonry/src/widget/root_widget.rs b/masonry/src/widget/root_widget.rs index 031a72a40..81c5c3826 100644 --- a/masonry/src/widget/root_widget.rs +++ b/masonry/src/widget/root_widget.rs @@ -20,15 +20,15 @@ pub struct RootWidget { } impl RootWidget { - pub fn new(widget: W) -> RootWidget { - RootWidget { + pub fn new(widget: W) -> Self { + Self { pod: WidgetPod::new(widget), } } // TODO - This help works around impedance mismatch between the types of Xilem and Masonry - pub fn from_pod(pod: WidgetPod) -> RootWidget { - RootWidget { pod } + pub fn from_pod(pod: WidgetPod) -> Self { + Self { pod } } } diff --git a/masonry/src/widget/sized_box.rs b/masonry/src/widget/sized_box.rs index 1154d06c1..c41687cc1 100644 --- a/masonry/src/widget/sized_box.rs +++ b/masonry/src/widget/sized_box.rs @@ -80,7 +80,7 @@ impl Padding { } /// A padding of zero for all edges. - pub const ZERO: Padding = Padding::all(0.); + pub const ZERO: Self = Self::all(0.); /// An empty padding which can be used as a sentinel value. /// @@ -88,7 +88,7 @@ impl Padding { /// they should use [`is_unset`](Self::is_unset) to determine that there were no modifications. /// /// Otherwise, this padding will behave as [`Padding::ZERO`]. - pub const UNSET: Padding = Padding::all(-0.0); + pub const UNSET: Self = Self::all(-0.0); /// Determine if self is [`Padding::UNSET`]. pub fn is_unset(self) -> bool { diff --git a/masonry/src/widget/spinner.rs b/masonry/src/widget/spinner.rs index a04bc23e8..430a4d70b 100644 --- a/masonry/src/widget/spinner.rs +++ b/masonry/src/widget/spinner.rs @@ -32,8 +32,8 @@ pub struct Spinner { // --- MARK: BUILDERS --- impl Spinner { /// Create a spinner widget - pub fn new() -> Spinner { - Spinner::default() + pub fn new() -> Self { + Self::default() } /// Builder-style method for setting the spinner's color. @@ -47,7 +47,7 @@ const DEFAULT_SPINNER_COLOR: Color = theme::TEXT_COLOR; impl Default for Spinner { fn default() -> Self { - Spinner { + Self { t: 0.0, color: DEFAULT_SPINNER_COLOR, } diff --git a/masonry/src/widget/split.rs b/masonry/src/widget/split.rs index 9b96b62cd..bebaf90e2 100644 --- a/masonry/src/widget/split.rs +++ b/masonry/src/widget/split.rs @@ -45,7 +45,7 @@ impl Split { /// Horizontal split axis means that the children are left and right. /// Vertical split axis means that the children are up and down. fn new(split_axis: Axis, child1: impl Widget + 'static, child2: impl Widget + 'static) -> Self { - Split { + Self { split_axis, split_point_chosen: 0.5, split_point_effective: 0.5, diff --git a/masonry/src/widget/text_area.rs b/masonry/src/widget/text_area.rs index bccd1cc32..86fb0b91e 100644 --- a/masonry/src/widget/text_area.rs +++ b/masonry/src/widget/text_area.rs @@ -137,7 +137,7 @@ impl TextArea { let mut editor = PlainEditor::new(theme::TEXT_SIZE_NORMAL); default_styles(editor.edit_styles()); editor.set_text(text); - TextArea { + Self { editor, rendered_generation: Generation::default(), last_click_time: None, diff --git a/masonry/src/widget/variable_label.rs b/masonry/src/widget/variable_label.rs index 4171b9572..26ab6151e 100644 --- a/masonry/src/widget/variable_label.rs +++ b/masonry/src/widget/variable_label.rs @@ -36,7 +36,7 @@ impl AnimatedF32 { /// Create a value which is not changing. pub fn stable(value: f32) -> Self { assert!(value.is_finite()); - AnimatedF32 { + Self { target: value, value, rate_per_millisecond: 0., @@ -117,7 +117,7 @@ pub enum AnimationStatus { impl AnimationStatus { pub fn is_completed(self) -> bool { - matches!(self, AnimationStatus::Completed) + matches!(self, Self::Completed) } } diff --git a/masonry/src/widget/widget.rs b/masonry/src/widget/widget.rs index 3134b86ae..a21b93052 100644 --- a/masonry/src/widget/widget.rs +++ b/masonry/src/widget/widget.rs @@ -361,10 +361,10 @@ impl WidgetId { /// /// You must ensure that a given `WidgetId` is only ever used for one /// widget at a time. - pub fn next() -> WidgetId { + pub fn next() -> Self { static WIDGET_ID_COUNTER: AtomicU64 = AtomicU64::new(1); let id = WIDGET_ID_COUNTER.fetch_add(1, Ordering::Relaxed); - WidgetId(id.try_into().unwrap()) + Self(id.try_into().unwrap()) } // TODO - Remove @@ -377,10 +377,10 @@ impl WidgetId { /// be the same as the raw value that is passed in; it will be /// `u64::max_value() - raw`. #[allow(clippy::missing_panics_doc)] // Can never panic - pub const fn reserved(raw: u16) -> WidgetId { + pub const fn reserved(raw: u16) -> Self { let id = u64::MAX - raw as u64; match NonZeroU64::new(id) { - Some(id) => WidgetId(id), + Some(id) => Self(id), // panic safety: u64::MAX - any u16 can never be zero None => unreachable!(), } @@ -392,14 +392,14 @@ impl WidgetId { } impl From for u64 { - fn from(id: WidgetId) -> u64 { + fn from(id: WidgetId) -> Self { id.0.into() } } impl From for accesskit::NodeId { - fn from(id: WidgetId) -> accesskit::NodeId { - accesskit::NodeId(id.0.into()) + fn from(id: WidgetId) -> Self { + Self(id.0.into()) } } diff --git a/masonry/src/widget/widget_pod.rs b/masonry/src/widget/widget_pod.rs index 85e81cacf..9228a9a09 100644 --- a/masonry/src/widget/widget_pod.rs +++ b/masonry/src/widget/widget_pod.rs @@ -35,13 +35,13 @@ impl WidgetPod { /// In a widget hierarchy, each widget is wrapped in a `WidgetPod` /// so it can participate in layout and event flow. The process of /// adding a child widget to a container should call this method. - pub fn new(inner: W) -> WidgetPod { + pub fn new(inner: W) -> Self { Self::new_with_id(inner, WidgetId::next()) } /// Create a new widget pod with fixed id. - pub fn new_with_id(inner: W, id: WidgetId) -> WidgetPod { - WidgetPod { + pub fn new_with_id(inner: W, id: WidgetId) -> Self { + Self { id, inner: WidgetPodInner::Created(inner), } diff --git a/masonry/src/widget/widget_ref.rs b/masonry/src/widget/widget_ref.rs index 87f23cde6..aa5689e29 100644 --- a/masonry/src/widget/widget_ref.rs +++ b/masonry/src/widget/widget_ref.rs @@ -146,9 +146,9 @@ impl<'w, W: Widget> WidgetRef<'w, W> { } } -impl<'w> WidgetRef<'w, dyn Widget> { +impl WidgetRef<'_, dyn Widget> { /// Recursively find child widget with given id. - pub fn find_widget_by_id(&self, id: WidgetId) -> Option> { + pub fn find_widget_by_id(&self, id: WidgetId) -> Option { if self.ctx.widget_state.id == id { Some(*self) } else { @@ -164,7 +164,7 @@ impl<'w> WidgetRef<'w, dyn Widget> { /// /// **pos** - the position in global coordinates (e.g. `(0,0)` is the top-left corner of the /// window). - pub fn find_widget_at_pos(&self, pos: Point) -> Option> { + pub fn find_widget_at_pos(&self, pos: Point) -> Option { let mut innermost_widget = *self; if !self.ctx.window_layout_rect().contains(pos) { diff --git a/masonry/src/widget/widget_state.rs b/masonry/src/widget/widget_state.rs index b1f7e50a2..a834b622f 100644 --- a/masonry/src/widget/widget_state.rs +++ b/masonry/src/widget/widget_state.rs @@ -151,8 +151,8 @@ pub(crate) struct WidgetState { } impl WidgetState { - pub(crate) fn new(id: WidgetId, widget_name: &'static str) -> WidgetState { - WidgetState { + pub(crate) fn new(id: WidgetId, widget_name: &'static str) -> Self { + Self { id, origin: Point::ORIGIN, window_origin: Point::ORIGIN, @@ -198,8 +198,8 @@ impl WidgetState { /// Create a dummy root state. /// /// This is useful for passes that need a parent state for the root widget. - pub(crate) fn synthetic(id: WidgetId, size: Size) -> WidgetState { - WidgetState { + pub(crate) fn synthetic(id: WidgetId, size: Size) -> Self { + Self { size, is_new: false, needs_layout: false, @@ -215,7 +215,7 @@ impl WidgetState { needs_update_stashed: false, children_changed: false, update_focus_chain: false, - ..WidgetState::new(id, "") + ..Self::new(id, "") } } @@ -226,7 +226,7 @@ impl WidgetState { // TODO: though this method takes child state mutably, child state currently isn't actually // mutated anymore. This method may start doing so again in the future, so keep taking &mut for // now. - pub(crate) fn merge_up(&mut self, child_state: &mut WidgetState) { + pub(crate) fn merge_up(&mut self, child_state: &mut Self) { self.needs_layout |= child_state.needs_layout; self.needs_compose |= child_state.needs_compose; self.needs_paint |= child_state.needs_paint; diff --git a/xilem/examples/calc.rs b/xilem/examples/calc.rs index 1e1f082f6..5126aaec5 100644 --- a/xilem/examples/calc.rs +++ b/xilem/examples/calc.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 //! A simple calculator example -#![expect(clippy::use_self, reason = "Deferred: Noisy")] #![expect(clippy::match_same_arms, reason = "Deferred: Noisy")] #![expect(clippy::cast_possible_truncation, reason = "Deferred: Noisy")] @@ -27,19 +26,19 @@ enum MathOperator { impl MathOperator { fn as_str(self) -> &'static str { match self { - MathOperator::Add => "+", - MathOperator::Subtract => "\u{2212}", - MathOperator::Multiply => "×", - MathOperator::Divide => "÷", + Self::Add => "+", + Self::Subtract => "\u{2212}", + Self::Multiply => "×", + Self::Divide => "÷", } } fn perform_op(self, num1: f64, num2: f64) -> f64 { match self { - MathOperator::Add => num1 + num2, - MathOperator::Subtract => num1 - num2, - MathOperator::Multiply => num1 * num2, - MathOperator::Divide => num1 / num2, + Self::Add => num1 + num2, + Self::Subtract => num1 - num2, + Self::Multiply => num1 * num2, + Self::Divide => num1 / num2, } } } diff --git a/xilem/examples/http_cats.rs b/xilem/examples/http_cats.rs index f3dd486dd..10bc610f1 100644 --- a/xilem/examples/http_cats.rs +++ b/xilem/examples/http_cats.rs @@ -4,7 +4,6 @@ //! An example demonstrating the use of Async web requests in Xilem to access the API. //! This also demonstrates image loading. -#![expect(clippy::use_self, reason = "Deferred: Noisy")] #![expect(clippy::match_same_arms, reason = "Deferred: Noisy")] #![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")] @@ -46,7 +45,7 @@ enum ImageState { } impl HttpCats { - fn view(&mut self) -> impl WidgetView { + fn view(&mut self) -> impl WidgetView { let left_column = sized_box(portal(flex(( prose("Status"), self.statuses @@ -135,7 +134,7 @@ impl HttpCats { } } }, - |state: &mut HttpCats, (code, image): (u32, Image)| { + |state: &mut Self, (code, image): (u32, Image)| { if let Some(status) = state.statuses.iter_mut().find(|it| it.code == code) { status.image = ImageState::Available(image); } else { @@ -231,7 +230,7 @@ impl Status { let mut lines = STATUS_CODES_CSV.lines(); let first_line = lines.next(); assert_eq!(first_line, Some("code,message")); - lines.flat_map(Status::parse_single).collect() + lines.flat_map(Self::parse_single).collect() } fn parse_single(line: &'static str) -> Option { diff --git a/xilem/src/lib.rs b/xilem/src/lib.rs index 8bcbc7427..7955052b0 100644 --- a/xilem/src/lib.rs +++ b/xilem/src/lib.rs @@ -28,7 +28,6 @@ #![expect(clippy::match_same_arms, reason = "Deferred: Noisy")] #![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")] #![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")] -#![expect(clippy::use_self, reason = "Deferred: Noisy")] // https://github.com/rust-lang/rust/pull/130025 #![allow(missing_docs, reason = "We have many as-yet undocumented items")] #![expect(clippy::missing_errors_doc, reason = "Can be quite noisy?")] @@ -85,7 +84,7 @@ where { pub fn new(state: State, logic: Logic) -> Self { let runtime = tokio::runtime::Runtime::new().unwrap(); - Xilem { + Self { state, logic, runtime, diff --git a/xilem/src/one_of.rs b/xilem/src/one_of.rs index 897170e09..ff0d4d28f 100644 --- a/xilem/src/one_of.rs +++ b/xilem/src/one_of.rs @@ -177,61 +177,61 @@ impl< fn register_children(&mut self, ctx: &mut RegisterCtx) { match self { - OneOfWidget::A(w) => ctx.register_child(w), - OneOfWidget::B(w) => ctx.register_child(w), - OneOfWidget::C(w) => ctx.register_child(w), - OneOfWidget::D(w) => ctx.register_child(w), - OneOfWidget::E(w) => ctx.register_child(w), - OneOfWidget::F(w) => ctx.register_child(w), - OneOfWidget::G(w) => ctx.register_child(w), - OneOfWidget::H(w) => ctx.register_child(w), - OneOfWidget::I(w) => ctx.register_child(w), + Self::A(w) => ctx.register_child(w), + Self::B(w) => ctx.register_child(w), + Self::C(w) => ctx.register_child(w), + Self::D(w) => ctx.register_child(w), + Self::E(w) => ctx.register_child(w), + Self::F(w) => ctx.register_child(w), + Self::G(w) => ctx.register_child(w), + Self::H(w) => ctx.register_child(w), + Self::I(w) => ctx.register_child(w), } } fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { match self { - OneOfWidget::A(w) => { + Self::A(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size } - OneOfWidget::B(w) => { + Self::B(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size } - OneOfWidget::C(w) => { + Self::C(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size } - OneOfWidget::D(w) => { + Self::D(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size } - OneOfWidget::E(w) => { + Self::E(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size } - OneOfWidget::F(w) => { + Self::F(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size } - OneOfWidget::G(w) => { + Self::G(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size } - OneOfWidget::H(w) => { + Self::H(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size } - OneOfWidget::I(w) => { + Self::I(w) => { let size = ctx.run_layout(w, bc); ctx.place_child(w, Point::ORIGIN); size @@ -249,15 +249,15 @@ impl< fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { match self { - OneOfWidget::A(w) => smallvec![w.id()], - OneOfWidget::B(w) => smallvec![w.id()], - OneOfWidget::C(w) => smallvec![w.id()], - OneOfWidget::D(w) => smallvec![w.id()], - OneOfWidget::E(w) => smallvec![w.id()], - OneOfWidget::F(w) => smallvec![w.id()], - OneOfWidget::G(w) => smallvec![w.id()], - OneOfWidget::H(w) => smallvec![w.id()], - OneOfWidget::I(w) => smallvec![w.id()], + Self::A(w) => smallvec![w.id()], + Self::B(w) => smallvec![w.id()], + Self::C(w) => smallvec![w.id()], + Self::D(w) => smallvec![w.id()], + Self::E(w) => smallvec![w.id()], + Self::F(w) => smallvec![w.id()], + Self::G(w) => smallvec![w.id()], + Self::H(w) => smallvec![w.id()], + Self::I(w) => smallvec![w.id()], } } } diff --git a/xilem/src/view/flex.rs b/xilem/src/view/flex.rs index e009fe8b2..36c368e91 100644 --- a/xilem/src/view/flex.rs +++ b/xilem/src/view/flex.rs @@ -199,14 +199,14 @@ impl ViewElement for FlexElement { type Mut<'w> = FlexElementMut<'w>; } -impl SuperElement for FlexElement { - fn upcast(_ctx: &mut ViewCtx, child: FlexElement) -> Self { +impl SuperElement for FlexElement { + fn upcast(_ctx: &mut ViewCtx, child: Self) -> Self { child } fn with_downcast_val( mut this: Mut, - f: impl FnOnce(Mut) -> R, + f: impl FnOnce(Mut) -> R, ) -> (Self::Mut<'_>, R) { let r = { let parent = this.parent.reborrow_mut(); @@ -222,7 +222,7 @@ impl SuperElement for FlexElement { impl SuperElement, ViewCtx> for FlexElement { fn upcast(ctx: &mut ViewCtx, child: Pod) -> Self { - FlexElement::Child(ctx.boxed_pod(child), FlexParams::default()) + Self::Child(ctx.boxed_pod(child), FlexParams::default()) } fn with_downcast_val( @@ -437,7 +437,7 @@ where V: WidgetView, { fn from(value: FlexItem) -> Self { - AnyFlexChild::Item(flex_item(value.view.boxed(), value.params)) + Self::Item(flex_item(value.view.boxed(), value.params)) } } @@ -510,7 +510,7 @@ pub enum FlexSpacer { impl From for AnyFlexChild { fn from(spacer: FlexSpacer) -> Self { - AnyFlexChild::Spacer(spacer) + Self::Spacer(spacer) } } @@ -524,8 +524,8 @@ impl View for FlexSpacer { fn build(&self, _ctx: &mut ViewCtx) -> (Self::Element, Self::ViewState) { let el = match self { - FlexSpacer::Fixed(len) => FlexElement::FixedSpacer(*len), - FlexSpacer::Flex(flex) => FlexElement::FlexSpacer(*flex), + Self::Fixed(len) => FlexElement::FixedSpacer(*len), + Self::Flex(flex) => FlexElement::FlexSpacer(*flex), }; (el, ()) } @@ -539,10 +539,10 @@ impl View for FlexSpacer { ) { if self != prev { match self { - FlexSpacer::Fixed(len) => { + Self::Fixed(len) => { widget::Flex::update_spacer_fixed(&mut element.parent, element.idx, *len); } - FlexSpacer::Flex(flex) => { + Self::Flex(flex) => { widget::Flex::update_spacer_flex(&mut element.parent, element.idx, *flex); } }; @@ -647,12 +647,12 @@ where fn build(&self, ctx: &mut ViewCtx) -> (Self::Element, Self::ViewState) { let generation = 0; let (element, view_state) = match self { - AnyFlexChild::Item(flex_item) => { + Self::Item(flex_item) => { let (element, state) = ctx.with_id(ViewId::new(generation), |ctx| flex_item.build(ctx)); (element, Some(state)) } - AnyFlexChild::Spacer(spacer) => { + Self::Spacer(spacer) => { // We know that the spacer doesn't need any id, as it doesn't receive or sends any messages // (Similar to `None` as a ViewSequence) let (element, ()) = View::<(), (), ViewCtx>::build(spacer, ctx); @@ -676,15 +676,15 @@ where mut element: Mut, ) { match (prev, self) { - (AnyFlexChild::Item(prev), AnyFlexChild::Item(this)) => { + (Self::Item(prev), Self::Item(this)) => { ctx.with_id(ViewId::new(view_state.generation), |ctx| { this.rebuild(prev, view_state.inner.as_mut().unwrap(), ctx, element); }); } - (AnyFlexChild::Spacer(prev), AnyFlexChild::Spacer(this)) => { + (Self::Spacer(prev), Self::Spacer(this)) => { View::<(), (), ViewCtx>::rebuild(this, prev, &mut (), ctx, element); } - (AnyFlexChild::Item(prev_flex_item), AnyFlexChild::Spacer(new_spacer)) => { + (Self::Item(prev_flex_item), Self::Spacer(new_spacer)) => { // Run teardown with the old path ctx.with_id(ViewId::new(view_state.generation), |ctx| { prev_flex_item.teardown( @@ -718,7 +718,7 @@ where FlexElement::Child(_, _) => unreachable!(), }; } - (AnyFlexChild::Spacer(prev_spacer), AnyFlexChild::Item(new_flex_item)) => { + (Self::Spacer(prev_spacer), Self::Item(new_flex_item)) => { View::<(), (), ViewCtx>::teardown( prev_spacer, &mut (), @@ -756,10 +756,10 @@ where element: Mut, ) { match self { - AnyFlexChild::Item(flex_item) => { + Self::Item(flex_item) => { flex_item.teardown(view_state.inner.as_mut().unwrap(), ctx, element); } - AnyFlexChild::Spacer(spacer) => { + Self::Spacer(spacer) => { View::<(), (), ViewCtx>::teardown(spacer, &mut (), ctx, element); } } @@ -779,7 +779,7 @@ where // The message was sent to a previous edition of the inner value return MessageResult::Stale(message); } - let AnyFlexChild::Item(flex_item) = self else { + let Self::Item(flex_item) = self else { unreachable!( "this should be unreachable as the generation was increased on the falling edge" ) diff --git a/xilem/src/view/grid.rs b/xilem/src/view/grid.rs index c68bff56a..c43aad40b 100644 --- a/xilem/src/view/grid.rs +++ b/xilem/src/view/grid.rs @@ -127,14 +127,14 @@ impl ViewElement for GridElement { } // Used to allow the item to be used as a generic item in ViewSequence. -impl SuperElement for GridElement { - fn upcast(_ctx: &mut ViewCtx, child: GridElement) -> Self { +impl SuperElement for GridElement { + fn upcast(_ctx: &mut ViewCtx, child: Self) -> Self { child } fn with_downcast_val( mut this: Mut, - f: impl FnOnce(Mut) -> R, + f: impl FnOnce(Mut) -> R, ) -> (Self::Mut<'_>, R) { let r = { let parent = this.parent.reborrow_mut(); @@ -155,7 +155,7 @@ impl SuperElement, ViewCtx> for GridElement { // There is not much else, beyond purposefully failing, that can be done here, // because there isn't enough information to determine an appropriate spot // for the widget. - GridElement::Child(ctx.boxed_pod(child), GridParams::new(1, 1, 1, 1)) + Self::Child(ctx.boxed_pod(child), GridParams::new(1, 1, 1, 1)) } fn with_downcast_val( diff --git a/xilem_web/src/lib.rs b/xilem_web/src/lib.rs index c9f7ae63a..74158fe7c 100644 --- a/xilem_web/src/lib.rs +++ b/xilem_web/src/lib.rs @@ -30,7 +30,6 @@ #![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")] #![expect(clippy::return_self_not_must_use, reason = "Deferred: Noisy")] #![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")] -#![expect(clippy::use_self, reason = "Deferred: Noisy")] // expect doesn't work here: https://github.com/rust-lang/rust/pull/130025 #![allow(missing_docs, reason = "We have many as-yet undocumented items")] #![expect(unreachable_pub, reason = "Potentially controversial code style")]