From 481db7f23cee09998059a053f976daf34fb64cb7 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Sat, 16 Aug 2025 21:27:47 +0200 Subject: [PATCH] refactor: pedantic cargo clippy, do not use Results for always-succeeding functions --- wgui/src/animation.rs | 28 +++--- wgui/src/components/button.rs | 8 +- wgui/src/components/checkbox.rs | 28 +++--- wgui/src/components/mod.rs | 3 +- wgui/src/components/slider.rs | 20 ++-- wgui/src/drawing.rs | 12 ++- wgui/src/event.rs | 33 ++++--- wgui/src/gfx/cmd.rs | 6 +- wgui/src/gfx/mod.rs | 4 +- wgui/src/gfx/pass.rs | 2 +- wgui/src/gfx/pipeline.rs | 10 +- wgui/src/i18n.rs | 2 +- wgui/src/layout.rs | 18 ++-- wgui/src/lib.rs | 19 ++++ wgui/src/parser/component_button.rs | 2 +- wgui/src/parser/component_checkbox.rs | 2 +- wgui/src/parser/component_slider.rs | 2 +- wgui/src/parser/mod.rs | 99 ++++++++----------- wgui/src/parser/style.rs | 6 +- wgui/src/parser/widget_div.rs | 6 +- wgui/src/parser/widget_label.rs | 6 +- wgui/src/parser/widget_rectangle.rs | 12 +-- wgui/src/parser/widget_sprite.rs | 6 +- wgui/src/renderer_vk/context.rs | 8 +- wgui/src/renderer_vk/model_buffer.rs | 6 +- wgui/src/renderer_vk/rect.rs | 6 +- wgui/src/renderer_vk/text/custom_glyph.rs | 34 ++++--- wgui/src/renderer_vk/text/mod.rs | 50 +++++----- wgui/src/renderer_vk/text/text_atlas.rs | 36 ++++--- wgui/src/renderer_vk/text/text_renderer.rs | 59 ++++++----- wgui/src/renderer_vk/util.rs | 4 +- wgui/src/renderer_vk/viewport.rs | 5 +- wgui/src/transform_stack.rs | 4 +- wgui/src/widget/div.rs | 2 +- wgui/src/widget/label.rs | 6 +- wgui/src/widget/mod.rs | 22 +++-- wgui/src/widget/rectangle.rs | 4 +- wgui/src/widget/sprite.rs | 7 +- wlx-overlay-s/src/backend/openxr/lines.rs | 4 +- wlx-overlay-s/src/backend/openxr/skybox.rs | 12 +-- wlx-overlay-s/src/main.rs | 1 + .../src/overlays/keyboard/builder.rs | 7 +- wlx-overlay-s/src/overlays/screen/capture.rs | 4 +- wlx-overlay-s/src/overlays/toast.rs | 11 +-- wlx-overlay-s/src/overlays/wayvr.rs | 4 +- 45 files changed, 320 insertions(+), 310 deletions(-) diff --git a/wgui/src/animation.rs b/wgui/src/animation.rs index e65e36b..a00205a 100644 --- a/wgui/src/animation.rs +++ b/wgui/src/animation.rs @@ -17,18 +17,18 @@ pub enum AnimationEasing { impl AnimationEasing { fn interpolate(&self, x: f32) -> f32 { match self { - AnimationEasing::Linear => x, - AnimationEasing::InQuad => x * x, - AnimationEasing::OutQuad => 1.0 - (1.0 - x) * (1.0 - x), - AnimationEasing::OutBack => { + Self::Linear => x, + Self::InQuad => x * x, + Self::OutQuad => 1.0 - (1.0 - x) * (1.0 - x), + Self::OutBack => { let a = 1.7; let b = a + 1.0; - 1.0 + b * (x - 1.0).powf(3.0) + a * (x - 1.0).powf(2.0) + 1.0 + b * (x - 1.0).powi(3) + a * (x - 1.0).powi(2) } - AnimationEasing::InBack => { + Self::InBack => { let a = 1.7; let b = a + 1.0; - b * x.powf(3.0) - a * x.powf(2.0) + b * x.powi(3) - a * x.powi(2) } } } @@ -46,7 +46,7 @@ pub type AnimationCallback = Box Self { - Animation::new_ex(target_widget, 0, ticks, easing, callback) + Self::new_ex(target_widget, 0, ticks, easing, callback) } pub fn new_ex( @@ -78,7 +78,7 @@ impl Animation { ) -> Self { Self { target_widget, - animation_id, + id: animation_id, callback, easing, ticks_duration: ticks, @@ -155,15 +155,15 @@ impl Animations { pub fn add(&mut self, anim: Animation) { // prevent running two animations at once - self.stop_by_widget(anim.target_widget, Some(anim.animation_id)); + self.stop_by_widget(anim.target_widget, Some(anim.id)); self.running_animations.push(anim); } - pub fn stop_by_widget(&mut self, widget_id: WidgetID, animation_id: Option) { + pub fn stop_by_widget(&mut self, widget_id: WidgetID, opt_animation_id: Option) { self.running_animations.retain(|anim| { - if let Some(animation_id) = &animation_id { + if let Some(animation_id) = &opt_animation_id { if anim.target_widget == widget_id { - anim.animation_id != *animation_id + anim.id != *animation_id } else { true } diff --git a/wgui/src/components/button.rs b/wgui/src/components/button.rs index a47f8c4..0bfbc62 100644 --- a/wgui/src/components/button.rs +++ b/wgui/src/components/button.rs @@ -265,7 +265,7 @@ pub fn construct( round: params.round, border_color: params.border_color, border: 2.0, - })?, + }), style, )?; @@ -287,10 +287,8 @@ pub fn construct( ..params.text_style }, }, - )?, - taffy::Style { - ..Default::default() - }, + ), + Default::default(), )?; let data = Rc::new(Data { diff --git a/wgui/src/components/checkbox.rs b/wgui/src/components/checkbox.rs index 470e6f1..0439d1f 100644 --- a/wgui/src/components/checkbox.rs +++ b/wgui/src/components/checkbox.rs @@ -150,7 +150,7 @@ fn anim_hover_out(state: Rc>, widget_id: WidgetID) -> Animation { } fn register_event_mouse_enter( - data: Rc, + data: &Rc, state: Rc>, listeners: &mut EventListenerCollection, listener_handles: &mut ListenerHandleVec, @@ -171,7 +171,7 @@ fn register_event_mouse_enter( } fn register_event_mouse_leave( - data: Rc, + data: &Rc, state: Rc>, listeners: &mut EventListenerCollection, listener_handles: &mut ListenerHandleVec, @@ -192,7 +192,7 @@ fn register_event_mouse_leave( } fn register_event_mouse_press( - data: Rc, + data: &Rc, state: Rc>, listeners: &mut EventListenerCollection, listener_handles: &mut ListenerHandleVec, @@ -289,7 +289,7 @@ pub fn construct( border_color: Color::new(1.0, 1.0, 1.0, 0.0), round: WLength::Units(5.0), ..Default::default() - })?, + }), style, )?; @@ -306,7 +306,7 @@ pub fn construct( round: WLength::Units(8.0), color: Color::new(1.0, 1.0, 1.0, 0.0), ..Default::default() - })?, + }), taffy::Style { size: box_size, padding: taffy::Rect::length(4.0), @@ -326,7 +326,7 @@ pub fn construct( COLOR_UNCHECKED }, ..Default::default() - })?, + }), taffy::Style { size: taffy::Size { width: percent(1.0), @@ -347,17 +347,15 @@ pub fn construct( ..Default::default() }, }, - )?, - taffy::Style { - ..Default::default() - }, + ), + Default::default(), )?; let data = Rc::new(Data { - node_label, id_container, - id_label, id_inner_box, + id_label, + node_label, }); let state = Rc::new(RefCell::new(State { @@ -369,9 +367,9 @@ pub fn construct( let mut base = ComponentBase::default(); - register_event_mouse_enter(data.clone(), state.clone(), listeners, &mut base.lhandles); - register_event_mouse_leave(data.clone(), state.clone(), listeners, &mut base.lhandles); - register_event_mouse_press(data.clone(), state.clone(), listeners, &mut base.lhandles); + register_event_mouse_enter(&data, state.clone(), listeners, &mut base.lhandles); + register_event_mouse_leave(&data, state.clone(), listeners, &mut base.lhandles); + register_event_mouse_press(&data, state.clone(), listeners, &mut base.lhandles); register_event_mouse_release(data.clone(), state.clone(), listeners, &mut base.lhandles); let checkbox = Rc::new(ComponentCheckbox { base, data, state }); diff --git a/wgui/src/components/mod.rs b/wgui/src/components/mod.rs index ddf798c..c877661 100644 --- a/wgui/src/components/mod.rs +++ b/wgui/src/components/mod.rs @@ -32,6 +32,7 @@ pub struct Component(pub Rc); pub type ComponentWeak = std::rc::Weak; impl Component { + pub fn weak(&self) -> ComponentWeak { Rc::downgrade(&self.0) } @@ -42,6 +43,6 @@ impl Component { } // safety: we already checked it above, should be safe to directly cast it - unsafe { Ok(Rc::from_raw(Rc::into_raw(self.0.clone()) as _)) } + unsafe { Ok(Rc::from_raw(Rc::into_raw(self.0.clone()).cast())) } } } diff --git a/wgui/src/components/slider.rs b/wgui/src/components/slider.rs index 15d97d1..12e911c 100644 --- a/wgui/src/components/slider.rs +++ b/wgui/src/components/slider.rs @@ -131,7 +131,7 @@ impl State { self.set_value(common.state, data, common.alterables, val); } - fn update_text(&self, i18n: &mut I18n, text: &mut WidgetLabel, value: f32) { + fn update_text(i18n: &mut I18n, text: &mut WidgetLabel, value: f32) { // round displayed value, should be sufficient for now text.set_text( i18n, @@ -156,7 +156,7 @@ impl State { state .widgets .call(data.slider_text_id, |label: &mut WidgetLabel| { - self.update_text(&mut state.globals.i18n(), label, value); + Self::update_text(&mut state.globals.i18n(), label, value); }); } } @@ -286,7 +286,7 @@ fn register_event_mouse_press( if state.hovered { state.dragging = true; - state.update_value_to_mouse(event_data, &data, common) + state.update_value_to_mouse(event_data, &data, common); } Ok(()) @@ -295,7 +295,7 @@ fn register_event_mouse_press( } fn register_event_mouse_release( - data: Rc, + data: &Rc, state: Rc>, listeners: &mut EventListenerCollection, listener_handles: &mut ListenerHandleVec, @@ -328,7 +328,7 @@ pub fn construct( style.min_size = style.size; style.max_size = style.size; - let (body_id, slider_body_node) = layout.add_child(parent, WidgetDiv::create()?, style)?; + let (body_id, slider_body_node) = layout.add_child(parent, WidgetDiv::create(), style)?; let (_background_id, _) = layout.add_child( body_id, @@ -338,7 +338,7 @@ pub fn construct( border_color: BODY_BORDER_COLOR, border: 2.0, ..Default::default() - })?, + }), taffy::Style { size: taffy::Size { width: percent(1.0), @@ -364,7 +364,7 @@ pub fn construct( // invisible outer handle body let (slider_handle_id, slider_handle_node) = - layout.add_child(body_id, WidgetDiv::create()?, slider_handle_style)?; + layout.add_child(body_id, WidgetDiv::create(), slider_handle_style)?; let (slider_handle_rect_id, _) = layout.add_child( slider_handle_id, @@ -374,7 +374,7 @@ pub fn construct( border: 2.0, round: WLength::Percent(1.0), ..Default::default() - })?, + }), taffy::Style { position: taffy::Position::Absolute, size: taffy::Size { @@ -406,7 +406,7 @@ pub fn construct( ..Default::default() }, }, - )?, + ), Default::default(), )?; @@ -427,7 +427,7 @@ pub fn construct( register_event_mouse_motion(data.clone(), state.clone(), listeners, &mut base.lhandles); register_event_mouse_press(data.clone(), state.clone(), listeners, &mut base.lhandles); register_event_mouse_leave(data.clone(), state.clone(), listeners, &mut base.lhandles); - register_event_mouse_release(data.clone(), state.clone(), listeners, &mut base.lhandles); + register_event_mouse_release(&data, state.clone(), listeners, &mut base.lhandles); let slider = Rc::new(ComponentSlider { base, data, state }); diff --git a/wgui/src/drawing.rs b/wgui/src/drawing.rs index 62bd87f..a3828a3 100644 --- a/wgui/src/drawing.rs +++ b/wgui/src/drawing.rs @@ -24,11 +24,11 @@ pub struct Boundary { } impl Boundary { - pub fn from_pos_size(pos: Vec2, size: Vec2) -> Self { + pub const fn from_pos_size(pos: Vec2, size: Vec2) -> Self { Self { pos, size } } - pub fn construct(transform_stack: &TransformStack) -> Self { + pub const fn construct(transform_stack: &TransformStack) -> Self { let transform = transform_stack.get(); Self { @@ -51,6 +51,7 @@ impl Color { Self { r, g, b, a } } + #[must_use] pub fn add_rgb(&self, n: f32) -> Self { Self { r: self.r + n, @@ -60,8 +61,9 @@ impl Color { } } - pub fn lerp(&self, other: &Color, n: f32) -> Color { - Color { + #[must_use] + pub fn lerp(&self, other: &Self, n: f32) -> Self { + Self { r: self.r * (1.0 - n) + other.r * n, g: self.g * (1.0 - n) + other.g * n, b: self.b * (1.0 - n) + other.b * n, @@ -164,7 +166,7 @@ fn draw_children( model: &glam::Mat4, ) { for node_id in layout.state.tree.child_ids(parent_node_id) { - let Some(widget_id) = layout.state.tree.get_node_context(node_id).cloned() else { + let Some(widget_id) = layout.state.tree.get_node_context(node_id).copied() else { debug_assert!(false); continue; }; diff --git a/wgui/src/event.rs b/wgui/src/event.rs index 11eceff..ca02e31 100644 --- a/wgui/src/event.rs +++ b/wgui/src/event.rs @@ -73,19 +73,20 @@ pub enum Event { } impl Event { - fn test_transform_pos(&self, transform: &Transform, pos: &Vec2) -> bool { + fn test_transform_pos(transform: &Transform, pos: Vec2) -> bool { pos.x >= transform.pos.x && pos.x < transform.pos.x + transform.dim.x && pos.y >= transform.pos.y && pos.y < transform.pos.y + transform.dim.y } + pub fn test_mouse_within_transform(&self, transform: &Transform) -> bool { match self { - Event::MouseDown(evt) => self.test_transform_pos(transform, &evt.pos), - Event::MouseMotion(evt) => self.test_transform_pos(transform, &evt.pos), - Event::MouseUp(evt) => self.test_transform_pos(transform, &evt.pos), - Event::MouseWheel(evt) => self.test_transform_pos(transform, &evt.pos), + Self::MouseDown(evt) => Self::test_transform_pos(transform, evt.pos), + Self::MouseMotion(evt) => Self::test_transform_pos(transform, evt.pos), + Self::MouseUp(evt) => Self::test_transform_pos(transform, evt.pos), + Self::MouseWheel(evt) => Self::test_transform_pos(transform, evt.pos), _ => false, } } @@ -102,7 +103,7 @@ pub struct EventAlterables { } impl EventAlterables { - pub fn mark_redraw(&mut self) { + pub const fn mark_redraw(&mut self) { self.needs_redraw = true; } @@ -114,7 +115,7 @@ impl EventAlterables { self.dirty_nodes.push(node_id); } - pub fn trigger_haptics(&mut self) { + pub const fn trigger_haptics(&mut self) { self.trigger_haptics = true; } @@ -128,7 +129,8 @@ pub struct CallbackDataCommon<'a> { pub alterables: &'a mut EventAlterables, } -impl<'a> CallbackDataCommon<'a> { +impl CallbackDataCommon<'_> { + pub fn i18n(&self) -> RefMut { self.state.globals.i18n() } @@ -151,15 +153,16 @@ pub enum CallbackMetadata { impl CallbackMetadata { // helper function - pub fn get_mouse_pos_absolute(&self) -> Option { + + pub const fn get_mouse_pos_absolute(&self) -> Option { match *self { - CallbackMetadata::None => None, - CallbackMetadata::MouseButton(b) => Some(b.pos), - CallbackMetadata::MousePosition(b) => Some(b.pos), - CallbackMetadata::Custom(_) => None, + Self::MouseButton(b) => Some(b.pos), + Self::MousePosition(b) => Some(b.pos), + Self::Custom(_) | Self::None => None, } } + pub fn get_mouse_pos_relative(&self, transform_stack: &TransformStack) -> Option { let mouse_pos_abs = self.get_mouse_pos_absolute()?; Some(mouse_pos_abs - transform_stack.get_pos()) @@ -206,6 +209,7 @@ pub struct EventListener { } impl EventListener { + pub fn callback_for_kind( &self, kind: EventListenerKind, @@ -291,7 +295,7 @@ impl EventListenerCollection { let mut count = 0; - for (_id, vec) in self.map.iter_mut() { + for (_id, vec) in &mut self.map { vec.0.retain(|listener| { if listener.handle.strong_count() != 0 { true @@ -307,6 +311,7 @@ impl EventListenerCollection { log::debug!("EventListenerCollection: cleaned-up {count} expired events"); } + pub fn get(&self, widget_id: WidgetID) -> Option<&EventListenerVec> { self.map.get(widget_id) } diff --git a/wgui/src/gfx/cmd.rs b/wgui/src/gfx/cmd.rs index c203571..500333e 100644 --- a/wgui/src/gfx/cmd.rs +++ b/wgui/src/gfx/cmd.rs @@ -124,7 +124,7 @@ impl WCommandBuffer { pub fn update_image( &mut self, - image: Arc, + image: &Arc, data: &[u8], offset: [u32; 3], extent: Option<[u32; 3]>, @@ -156,9 +156,9 @@ impl WCommandBuffer { pub fn copy_image( &mut self, - src: Arc, + src: &Arc, src_offset: [u32; 3], - dst: Arc, + dst: &Arc, dst_offset: [u32; 3], extent: Option<[u32; 3]>, ) -> anyhow::Result<()> { diff --git a/wgui/src/gfx/mod.rs b/wgui/src/gfx/mod.rs index 5f7a06d..1ddd4ed 100644 --- a/wgui/src/gfx/mod.rs +++ b/wgui/src/gfx/mod.rs @@ -181,8 +181,8 @@ impl WGfx { pub fn create_pipeline( self: &Arc, - vert: Arc, - frag: Arc, + vert: &Arc, + frag: &Arc, format: Format, blend: Option, topology: PrimitiveTopology, diff --git a/wgui/src/gfx/pass.rs b/wgui/src/gfx/pass.rs index 3d920a9..8318286 100644 --- a/wgui/src/gfx/pass.rs +++ b/wgui/src/gfx/pass.rs @@ -32,7 +32,7 @@ where V: BufferContents + Vertex, { pub(super) fn new( - pipeline: Arc>, + pipeline: &Arc>, dimensions: [f32; 2], vertex_buffer: Subbuffer<[V]>, vertices: Range, diff --git a/wgui/src/gfx/pipeline.rs b/wgui/src/gfx/pipeline.rs index 425e97e..6813b26 100644 --- a/wgui/src/gfx/pipeline.rs +++ b/wgui/src/gfx/pipeline.rs @@ -105,6 +105,7 @@ where }) } + pub fn inner(&self) -> Arc { self.pipeline.clone() } @@ -149,6 +150,7 @@ where )?) } + #[allow(clippy::needless_pass_by_value)] pub fn uniform_buffer_upload( &self, set: usize, @@ -183,8 +185,8 @@ where { pub(super) fn new_with_vert_input( graphics: Arc, - vert: Arc, - frag: Arc, + vert: &Arc, + frag: &Arc, format: Format, blend: Option, topology: PrimitiveTopology, @@ -199,7 +201,7 @@ where V::per_vertex().definition(&vert_entry_point)? }); - WGfxPipeline::new_from_stages( + Self::new_from_stages( graphics, format, blend, @@ -219,7 +221,7 @@ where descriptor_sets: Vec>, ) -> anyhow::Result> { WGfxPass::new( - self.clone(), + &self.clone(), dimensions, vertex_buffer, vertices, diff --git a/wgui/src/i18n.rs b/wgui/src/i18n.rs index d4bed84..a61cc02 100644 --- a/wgui/src/i18n.rs +++ b/wgui/src/i18n.rs @@ -93,8 +93,8 @@ impl I18n { let json_root_translated = serde_json::from_str(str::from_utf8(&data_translated)?)?; Ok(Self { - json_root_fallback, json_root_translated, + json_root_fallback, }) } diff --git a/wgui/src/layout.rs b/wgui/src/layout.rs index 129baaa..0d29613 100644 --- a/wgui/src/layout.rs +++ b/wgui/src/layout.rs @@ -186,7 +186,7 @@ impl Layout { user_data: &mut (&mut U1, &mut U2), ) -> anyhow::Result<()> { let l = self.state.tree.layout(node_id)?; - let Some(widget_id) = self.state.tree.get_node_context(node_id).cloned() else { + let Some(widget_id) = self.state.tree.get_node_context(node_id).copied() else { anyhow::bail!("invalid widget ID"); }; @@ -230,13 +230,9 @@ impl Layout { widget::EventResult::Pass => { // go on } - widget::EventResult::Consumed => { - iter_children = false; - } - widget::EventResult::Outside => { - iter_children = false; - } - widget::EventResult::Unused => { + widget::EventResult::Consumed + | widget::EventResult::Outside + | widget::EventResult::Unused => { iter_children = false; } } @@ -252,7 +248,7 @@ impl Layout { Ok(()) } - pub fn check_toggle_needs_redraw(&mut self) -> bool { + pub const fn check_toggle_needs_redraw(&mut self) -> bool { if self.needs_redraw { self.needs_redraw = false; true @@ -261,7 +257,7 @@ impl Layout { } } - pub fn check_toggle_haptics_triggered(&mut self) -> bool { + pub const fn check_toggle_haptics_triggered(&mut self) -> bool { if self.haptics_triggered { self.haptics_triggered = false; true @@ -306,7 +302,7 @@ impl Layout { &mut state.widgets, &mut state.nodes, None, // no parent - WidgetDiv::create()?, + WidgetDiv::create(), taffy::Style { size: taffy::Size::auto(), ..Default::default() diff --git a/wgui/src/lib.rs b/wgui/src/lib.rs index c4054c1..8e4ad16 100644 --- a/wgui/src/lib.rs +++ b/wgui/src/lib.rs @@ -1,3 +1,22 @@ +#![warn(clippy::all, clippy::pedantic, clippy::nursery)] +#![allow( + clippy::suboptimal_flops, + clippy::cast_precision_loss, + clippy::missing_errors_doc, + clippy::default_trait_access, + clippy::missing_panics_doc, + clippy::cast_possible_wrap, + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + clippy::items_after_statements, + clippy::future_not_send, + clippy::must_use_candidate, + clippy::implicit_hasher, + clippy::option_if_let_else, + clippy::significant_drop_tightening, + clippy::float_cmp +)] + pub mod animation; pub mod any; pub mod assets; diff --git a/wgui/src/parser/component_button.rs b/wgui/src/parser/component_button.rs index 97d94c6..c38929a 100644 --- a/wgui/src/parser/component_button.rs +++ b/wgui/src/parser/component_button.rs @@ -69,7 +69,7 @@ pub fn parse_component_button<'a, U1, U2>( }, )?; - process_component(file, ctx, node, Component(component))?; + process_component(file, ctx, node, Component(component)); Ok(()) } diff --git a/wgui/src/parser/component_checkbox.rs b/wgui/src/parser/component_checkbox.rs index 48a7660..1039c9c 100644 --- a/wgui/src/parser/component_checkbox.rs +++ b/wgui/src/parser/component_checkbox.rs @@ -51,7 +51,7 @@ pub fn parse_component_checkbox<'a, U1, U2>( }, )?; - process_component(file, ctx, node, Component(component))?; + process_component(file, ctx, node, Component(component)); Ok(()) } diff --git a/wgui/src/parser/component_slider.rs b/wgui/src/parser/component_slider.rs index eaef942..de96de1 100644 --- a/wgui/src/parser/component_slider.rs +++ b/wgui/src/parser/component_slider.rs @@ -48,7 +48,7 @@ pub fn parse_component_slider<'a, U1, U2>( }, )?; - process_component(file, ctx, node, Component(component))?; + process_component(file, ctx, node, Component(component)); Ok(()) } diff --git a/wgui/src/parser/mod.rs b/wgui/src/parser/mod.rs index bb368ee..3547e09 100644 --- a/wgui/src/parser/mod.rs +++ b/wgui/src/parser/mod.rs @@ -84,7 +84,7 @@ impl ParserState { } // safety: we already checked it above, should be safe to directly cast it - unsafe { Ok(Rc::from_raw(Rc::into_raw(component.0) as _)) } + unsafe { Ok(Rc::from_raw(Rc::into_raw(component.0).cast())) } } pub fn get_widget_id(&self, id: &str) -> anyhow::Result { @@ -135,7 +135,7 @@ impl ParserState { }; parse_widget_other_internal( - template.clone(), + &template.clone(), template_parameters, &file, &mut ctx, @@ -239,11 +239,11 @@ fn parse_val(value: &Rc) -> Option { } fn is_percent(value: &str) -> bool { - value.ends_with("%") + value.ends_with('%') } fn parse_percent(value: &str) -> Option { - let Some(val_str) = value.split("%").next() else { + let Some(val_str) = value.split('%').next() else { print_invalid_value(value); return None; }; @@ -295,7 +295,7 @@ where } fn parse_widget_other_internal( - template: Rc