From 88d188a794839f08a23ca01e4d363cec8198c682 Mon Sep 17 00:00:00 2001 From: Franz Dietrich Date: Mon, 20 Oct 2025 14:46:04 +0200 Subject: [PATCH] small fixes for clippy compliance --- turtle-lib-macros/src/lib.rs | 2 +- turtle-lib/src/builders.rs | 2 +- turtle-lib/src/commands_channel.rs | 12 +++++++----- turtle-lib/src/drawing.rs | 4 ++-- turtle-lib/src/execution.rs | 1 + turtle-lib/src/lib.rs | 6 +++--- turtle-lib/src/state.rs | 12 ++++++------ turtle-lib/src/tessellation.rs | 1 + turtle-lib/src/tweening.rs | 20 +++----------------- 9 files changed, 25 insertions(+), 35 deletions(-) diff --git a/turtle-lib-macros/src/lib.rs b/turtle-lib-macros/src/lib.rs index ad11367..6a292b3 100644 --- a/turtle-lib-macros/src/lib.rs +++ b/turtle-lib-macros/src/lib.rs @@ -32,7 +32,7 @@ use syn::{parse_macro_input, ItemFn}; /// } /// ``` /// -/// If you need macroquad types not re-exported by turtle_lib: +/// If you need macroquad types not re-exported by `turtle_lib`: /// /// ```ignore /// use macroquad::prelude::SKYBLUE; // Import specific items diff --git a/turtle-lib/src/builders.rs b/turtle-lib/src/builders.rs index ba87891..f92efcd 100644 --- a/turtle-lib/src/builders.rs +++ b/turtle-lib/src/builders.rs @@ -268,7 +268,7 @@ impl TurtlePlan { /// /// Speed controls how fast the turtle moves during animations: /// - Values `>= 1000`: Instant mode - commands execute immediately without animation. - /// The bigger the number, the more segments are drawn per frame. + /// The bigger the number, the more segments are drawn per frame. /// - Values `< 1000`: Animated mode - turtle moves at specified pixels per second /// /// You can dynamically switch between instant and animated modes during execution. diff --git a/turtle-lib/src/commands_channel.rs b/turtle-lib/src/commands_channel.rs index ac02e73..0b72d53 100644 --- a/turtle-lib/src/commands_channel.rs +++ b/turtle-lib/src/commands_channel.rs @@ -112,7 +112,7 @@ impl TurtleCommandSender { pub fn send(&self, queue: CommandQueue) -> Result<(), String> { self.tx .send(queue) - .map_err(|e| format!("Channel disconnected: {}", e)) + .map_err(|e| format!("Channel disconnected: {e}")) } /// Send commands (non-blocking) @@ -137,7 +137,7 @@ impl TurtleCommandSender { pub fn try_send(&self, queue: CommandQueue) -> Result<(), String> { self.tx .try_send(queue) - .map_err(|e| format!("Failed to send: {}", e)) + .map_err(|e| format!("Failed to send: {e}")) } } @@ -165,6 +165,7 @@ impl TurtleCommandReceiver { /// } /// # } /// ``` + #[must_use] pub fn recv_all(&self) -> Vec { self.rx.try_iter().collect() } @@ -192,14 +193,14 @@ impl TurtleCommandReceiver { /// /// The tuple represents (sender, receiver) where: /// - Sender goes to game logic threads (cloneable, can be distributed) -/// - Receiver stays in the render thread (part of TurtleApp internally) +/// - Receiver stays in the render thread (part of `TurtleApp` internally) /// /// # Arguments /// * `turtle_id` - The ID of the turtle this channel is for (must be valid) /// * `buffer_size` - Maximum number of pending command batches before sender blocks /// /// # Panics -/// Panics if buffer_size is 0. +/// Panics if `buffer_size` is 0. /// /// # Examples /// ```no_run @@ -207,9 +208,10 @@ impl TurtleCommandReceiver { /// # fn example() { /// let (tx, _rx) = turtle_command_channel(0, 100); /// // Sender goes to game threads -/// // Receiver stays in render thread (or TurtleApp) +/// // Receiver stays in render thread (or `TurtleApp`) /// # } /// ``` +#[must_use] pub fn turtle_command_channel( turtle_id: usize, buffer_size: usize, diff --git a/turtle-lib/src/drawing.rs b/turtle-lib/src/drawing.rs index a1a9237..fb208a5 100644 --- a/turtle-lib/src/drawing.rs +++ b/turtle-lib/src/drawing.rs @@ -93,7 +93,7 @@ pub fn render_world_with_tweens(world: &TurtleWorld, zoom_level: f32) { } // Draw in-progress tween lines for all active tweens - for turtle in world.turtles.iter() { + for turtle in &world.turtles { if let Some(tween) = turtle.tween_controller.current_tween() { // Only draw if pen is down if tween.start_params.pen_down { @@ -132,7 +132,7 @@ pub fn render_world_with_tweens(world: &TurtleWorld, zoom_level: f32) { } // Draw live fill preview for all turtles that are currently filling - for turtle in world.turtles.iter() { + for turtle in &world.turtles { if let Some(ref fill_state) = turtle.filling { // Build all contours: completed contours + current contour with animation let mut all_contours: Vec> = Vec::new(); diff --git a/turtle-lib/src/execution.rs b/turtle-lib/src/execution.rs index 6eab70f..421621e 100644 --- a/turtle-lib/src/execution.rs +++ b/turtle-lib/src/execution.rs @@ -11,6 +11,7 @@ use crate::general::AnimationSpeed; /// Execute side effects for commands that don't involve movement /// Returns true if the command was handled (caller should skip movement processing) +#[allow(clippy::too_many_lines)] pub fn execute_command_side_effects(command: &TurtleCommand, state: &mut Turtle) -> bool { match command { TurtleCommand::BeginFill => { diff --git a/turtle-lib/src/lib.rs b/turtle-lib/src/lib.rs index ccde09e..052a80d 100644 --- a/turtle-lib/src/lib.rs +++ b/turtle-lib/src/lib.rs @@ -118,7 +118,7 @@ impl TurtleApp { /// /// # Returns /// A `TurtleCommandSender` that can be cloned and sent to game logic threads. - /// The turtle is automatically managed by TurtleApp. + /// The turtle is automatically managed by `TurtleApp`. /// /// # Examples /// ```no_run @@ -236,7 +236,7 @@ impl TurtleApp { } } - /// Append commands from a CommandQueue to a turtle's animation queue + /// Append commands from a `CommandQueue` to a turtle's animation queue /// /// Used internally by `process_commands()` and can be used directly /// when you have a `CommandQueue` instead of a `TurtlePlan`. @@ -258,7 +258,7 @@ impl TurtleApp { self.handle_mouse_zoom(); // Update all turtles' tween controllers - for turtle in self.world.turtles.iter_mut() { + for turtle in &mut self.world.turtles { // Extract draw_commands and controller temporarily to avoid borrow conflicts // Update the controller diff --git a/turtle-lib/src/state.rs b/turtle-lib/src/state.rs index 7590894..9e90a84 100644 --- a/turtle-lib/src/state.rs +++ b/turtle-lib/src/state.rs @@ -38,7 +38,7 @@ pub struct TurtleParams { } impl Default for TurtleParams { - /// Create TurtleParams from default values + /// Create `TurtleParams` from default values fn default() -> Self { Self { position: vec2(0.0, 0.0), @@ -92,7 +92,7 @@ impl Turtle { Angle::radians(self.params.heading) } - /// Reset turtle to default state (preserves turtle_id and queued commands) + /// Reset turtle to default state (preserves `turtle_id` and queued commands) pub fn reset(&mut self) { // Clear all drawings self.commands.clear(); @@ -316,10 +316,10 @@ impl TurtleWorld { /// Add a new turtle and return its ID pub fn add_turtle(&mut self) -> usize { let turtle_id = self.turtles.len(); - let mut new_turtle = Turtle::default(); - new_turtle.turtle_id = turtle_id; - new_turtle.tween_controller = - TweenController::new(CommandQueue::new(), AnimationSpeed::default()); + let new_turtle = Turtle { + turtle_id, + ..Default::default() + }; self.turtles.push(new_turtle); turtle_id } diff --git a/turtle-lib/src/tessellation.rs b/turtle-lib/src/tessellation.rs index 433a2ee..214f402 100644 --- a/turtle-lib/src/tessellation.rs +++ b/turtle-lib/src/tessellation.rs @@ -294,6 +294,7 @@ pub fn tessellate_circle( /// # Errors /// /// Returns an error if tessellation fails. +#[allow(clippy::too_many_arguments)] pub fn tessellate_arc( center: Vec2, radius: f32, diff --git a/turtle-lib/src/tweening.rs b/turtle-lib/src/tweening.rs index e39396f..e446035 100644 --- a/turtle-lib/src/tweening.rs +++ b/turtle-lib/src/tweening.rs @@ -44,23 +44,13 @@ impl From for Vec2 { } /// Controls tweening of turtle commands -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct TweenController { queue: CommandQueue, current_tween: Option, speed: AnimationSpeed, } -impl Default for TweenController { - fn default() -> Self { - Self { - queue: CommandQueue::new(), - current_tween: None, - speed: AnimationSpeed::default(), - } - } -} - #[derive(Clone, Debug)] pub struct CommandTween { pub turtle_id: usize, @@ -98,6 +88,7 @@ impl TweenController { /// Update the tween, returns `Vec` of (`command`, `start_state`, `end_state`) for all completed commands this frame /// Also takes commands vec to handle side effects like fill operations /// Each `command` has its own `start_state` and `end_state` pair + #[allow(clippy::too_many_lines)] pub fn update(state: &mut Turtle) -> Vec<(TurtleCommand, TurtleParams, TurtleParams)> { // In instant mode, execute commands up to the draw calls per frame limit if let AnimationSpeed::Instant(max_draw_calls) = state.tween_controller.speed { @@ -106,12 +97,7 @@ impl TweenController { let mut draw_call_count = 0; // Consume commands from the real queue so the current_index advances - loop { - let command = match state.tween_controller.queue.next() { - Some(cmd) => cmd, - None => break, - }; - + while let Some(command) = state.tween_controller.queue.next() { // Handle SetSpeed command to potentially switch modes if let TurtleCommand::SetSpeed(new_speed) = &command { state.params.speed = *new_speed;