From 193e729ff4eec5dc572f97378556cb6be82edab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20P=2E=20Bezerra?= Date: Sun, 19 Nov 2023 11:43:53 -0300 Subject: [PATCH] Refac unnecessary `ref mut` pattern matching --- examples/draw/draw_arrow.rs | 14 ++++++++------ examples/laser/laser_frame_stream_gui.rs | 2 +- examples/ui/egui/circle_packing.rs | 10 +++++----- examples/ui/egui/tune_color.rs | 8 ++++---- generative_design/shape/p_2_1_5_03.rs | 2 +- nannou/src/draw/drawing.rs | 12 ++++++------ nannou/src/draw/primitive/text.rs | 8 ++++---- nannou/src/draw/properties/spatial/orientation.rs | 4 ++-- nannou/src/text/glyph.rs | 2 +- nannou_audio/src/requester.rs | 8 ++++---- nannou_audio/src/stream/input.rs | 2 +- nannou_audio/src/stream/output.rs | 2 +- nannou_core/src/geom/ellipse.rs | 5 +---- nannou_egui_demo_app/src/main.rs | 6 +++--- nannou_isf/src/pipeline.rs | 2 +- nannou_laser/src/ilda_idtf.rs | 8 ++++---- scripts/set_version/main.rs | 6 +++--- 17 files changed, 50 insertions(+), 51 deletions(-) diff --git a/examples/draw/draw_arrow.rs b/examples/draw/draw_arrow.rs index a10dad9ee..07c2894e8 100644 --- a/examples/draw/draw_arrow.rs +++ b/examples/draw/draw_arrow.rs @@ -12,12 +12,14 @@ fn view(app: &App, frame: Frame) { for r in r.subdivisions_iter() { for r in r.subdivisions_iter() { for r in r.subdivisions_iter() { - let side = r.w().min(r.h()); - let start = r.xy(); - let start_to_mouse = app.mouse.position() - start; - let target_mag = start_to_mouse.length().min(side * 0.5); - let end = start + start_to_mouse.normalize_or_zero() * target_mag; - draw.arrow().weight(5.0).points(start, end); + for r in r.subdivisions_iter() { + let side = r.w().min(r.h()); + let start = r.xy(); + let start_to_mouse = app.mouse.position() - start; + let target_mag = start_to_mouse.length().min(side * 0.5); + let end = start + start_to_mouse.normalize_or_zero() * target_mag; + draw.arrow().weight(5.0).points(start, end); + } } } } diff --git a/examples/laser/laser_frame_stream_gui.rs b/examples/laser/laser_frame_stream_gui.rs index f8e11f043..a1fc2c4d2 100644 --- a/examples/laser/laser_frame_stream_gui.rs +++ b/examples/laser/laser_frame_stream_gui.rs @@ -326,7 +326,7 @@ fn update(_app: &App, model: &mut Model, update: Update) { ref mut egui, ref laser_streams, ref mut laser_model, - ref mut laser_settings, + laser_settings, .. } = *model; diff --git a/examples/ui/egui/circle_packing.rs b/examples/ui/egui/circle_packing.rs index 3a9c0f6d1..ff7810850 100644 --- a/examples/ui/egui/circle_packing.rs +++ b/examples/ui/egui/circle_packing.rs @@ -52,11 +52,11 @@ fn model(app: &App) -> Model { fn update(_app: &App, model: &mut Model, update: Update) { let Model { - ref mut egui, - ref mut settings, - ref mut circles, + egui, + settings, + circles, .. - } = *model; + } = model; egui.set_elapsed_time(update.since_start); let ctx = egui.begin_frame(); @@ -72,7 +72,7 @@ fn update(_app: &App, model: &mut Model, update: Update) { .add(egui::Slider::new(&mut settings.circle_count, 0..=2000).text("circle count")) .changed(); changed |= ui.button("Generate").clicked(); - if changed { + if !changed { *circles = generate_circles(settings); } }); diff --git a/examples/ui/egui/tune_color.rs b/examples/ui/egui/tune_color.rs index 6e7b9e4b0..4414ad64b 100644 --- a/examples/ui/egui/tune_color.rs +++ b/examples/ui/egui/tune_color.rs @@ -36,10 +36,10 @@ fn model(app: &App) -> Model { fn update(_app: &App, model: &mut Model, update: Update) { let Model { - ref mut egui, - ref mut radius, - ref mut color, - } = *model; + egui, + radius, + color, + } = model; egui.set_elapsed_time(update.since_start); let ctx = egui.begin_frame(); diff --git a/generative_design/shape/p_2_1_5_03.rs b/generative_design/shape/p_2_1_5_03.rs index ce88cd2a5..db6e8bcb4 100644 --- a/generative_design/shape/p_2_1_5_03.rs +++ b/generative_design/shape/p_2_1_5_03.rs @@ -110,7 +110,7 @@ fn model(app: &App) -> Model { } fn update(app: &App, model: &mut Model, _update: Update) { - if let Some(ref mut s) = model.new_shape { + if let Some(s) = model.new_shape { s.x2 = app.mouse.x; s.y2 = app.mouse.y; s.h = model.shape_height; diff --git a/nannou/src/draw/drawing.rs b/nannou/src/draw/drawing.rs index 9b902039a..255cceb77 100644 --- a/nannou/src/draw/drawing.rs +++ b/nannou/src/draw/drawing.rs @@ -73,12 +73,12 @@ impl<'a> DrawingContext<'a> { // Initialise the DrawingContext from the draw's IntermediaryState. pub(crate) fn from_intermediary_state(state: &'a mut super::IntermediaryState) -> Self { let super::IntermediaryState { - ref mut intermediary_mesh, - ref mut path_event_buffer, - ref mut path_points_colored_buffer, - ref mut path_points_textured_buffer, - ref mut text_buffer, - } = *state; + intermediary_mesh, + path_event_buffer, + path_points_colored_buffer, + path_points_textured_buffer, + text_buffer, + } = state; DrawingContext { mesh: intermediary_mesh, path_event_buffer: path_event_buffer, diff --git a/nannou/src/draw/primitive/text.rs b/nannou/src/draw/primitive/text.rs index f031bcc57..be5639090 100644 --- a/nannou/src/draw/primitive/text.rs +++ b/nannou/src/draw/primitive/text.rs @@ -310,10 +310,10 @@ impl draw::renderer::RenderPrimitive for Text { { let draw::renderer::RenderContext { glyph_cache: - &mut draw::renderer::GlyphCache { - ref mut cache, - ref mut pixel_buffer, - ref mut requires_upload, + draw::renderer::GlyphCache { + cache, + pixel_buffer, + requires_upload, .. }, .. diff --git a/nannou/src/draw/properties/spatial/orientation.rs b/nannou/src/draw/properties/spatial/orientation.rs index c312189eb..0859f572b 100644 --- a/nannou/src/draw/properties/spatial/orientation.rs +++ b/nannou/src/draw/properties/spatial/orientation.rs @@ -181,8 +181,8 @@ impl Default for Properties { // Expects the `Axes` variant from the given properties. fn expect_axes(p: &mut Properties) -> &mut Vec3 { - match *p { - Properties::Axes(ref mut axes) => axes, + match p { + Properties::Axes(axes) => axes, Properties::LookAt(_) => panic!("expected `Axes`, found `LookAt`"), Properties::Quat(_) => panic!("expected `Axes`, found `Quat`"), } diff --git a/nannou/src/text/glyph.rs b/nannou/src/text/glyph.rs index 785160788..e7984b12a 100644 --- a/nannou/src/text/glyph.rs +++ b/nannou/src/text/glyph.rs @@ -59,7 +59,7 @@ struct ContourPathEvents { impl<'a, 'b> Iterator for Rects<'a, 'b> { type Item = (ScaledGlyph<'a>, Rect); fn next(&mut self) -> Option { - let Rects { ref mut layout, y } = *self; + let Rects { layout, y } = self; layout.next().map(|g| { let left = g.position().x; let (right, height) = g diff --git a/nannou_audio/src/requester.rs b/nannou_audio/src/requester.rs index 9533daa5e..887e1094a 100644 --- a/nannou_audio/src/requester.rs +++ b/nannou_audio/src/requester.rs @@ -48,16 +48,16 @@ where FR: stream::output::RenderFn, { let Requester { - ref mut samples, + samples, num_frames, - ref mut pending_range, - } = *self; + pending_range, + } = self; // Ensure that the buffer length makes sense given the number of channels. assert_eq!(output.len() % channels, 0); // Determine the number of samples in the buffer. - let num_samples = num_frames * channels; + let num_samples = *num_frames * channels; // if `output` is empty, there's nothing to fill. if output.is_empty() { diff --git a/nannou_audio/src/stream/input.rs b/nannou_audio/src/stream/input.rs index f19415020..402e6f1d3 100644 --- a/nannou_audio/src/stream/input.rs +++ b/nannou_audio/src/stream/input.rs @@ -220,7 +220,7 @@ impl Builder { // Wrap the user's error function. let err_fn = move |err| { if let Ok(mut guard) = model_error.lock() { - if let Some(ref mut model) = *guard { + if let Some(model) = guard.as_mut() { error(model, err); } } diff --git a/nannou_audio/src/stream/output.rs b/nannou_audio/src/stream/output.rs index 66cb46f6a..847db7278 100644 --- a/nannou_audio/src/stream/output.rs +++ b/nannou_audio/src/stream/output.rs @@ -219,7 +219,7 @@ impl Builder { // Wrap the user's error function. let err_fn = move |err| { if let Ok(mut guard) = model_error.lock() { - if let Some(ref mut model) = *guard { + if let Some(model) = guard.as_mut() { error(model, err); } } diff --git a/nannou_core/src/geom/ellipse.rs b/nannou_core/src/geom/ellipse.rs index 58c55711c..f170e7677 100644 --- a/nannou_core/src/geom/ellipse.rs +++ b/nannou_core/src/geom/ellipse.rs @@ -357,10 +357,7 @@ where { type Item = Tri<[S; 2]>; fn next(&mut self) -> Option { - let Triangles { - ref mut points, - ref mut last, - } = *self; + let Triangles { points, last } = self; points.next().map(|next| { let triangle = Tri([points.middle, *last, next]); *last = next; diff --git a/nannou_egui_demo_app/src/main.rs b/nannou_egui_demo_app/src/main.rs index 7c91a4a5c..c9f079626 100644 --- a/nannou_egui_demo_app/src/main.rs +++ b/nannou_egui_demo_app/src/main.rs @@ -37,10 +37,10 @@ fn raw_window_event(_app: &App, model: &mut Model, event: &nannou::winit::event: fn update(app: &App, model: &mut Model, update: Update) { let Model { - ref mut egui, - ref mut egui_demo_app, + egui, + egui_demo_app, .. - } = *model; + } = model; egui.set_elapsed_time(update.since_start); let proxy = app.create_proxy(); egui.do_frame_with_epi_frame(proxy, |ctx, frame| { diff --git a/nannou_isf/src/pipeline.rs b/nannou_isf/src/pipeline.rs index 3f81a3adf..2b9b951dd 100644 --- a/nannou_isf/src/pipeline.rs +++ b/nannou_isf/src/pipeline.rs @@ -382,7 +382,7 @@ impl IsfInputData { (IsfInputData::Float(_), isf::InputType::Float(_)) => {} (IsfInputData::Point2d(_), isf::InputType::Point2d(_)) => {} (IsfInputData::Color(_), isf::InputType::Color(_)) => {} - (IsfInputData::Image(ref mut state), isf::InputType::Image) => { + (IsfInputData::Image(state), isf::InputType::Image) => { if let Some(img_path) = image_paths(images_path).next() { state.update(device, encoder, image_loader, img_path); } diff --git a/nannou_laser/src/ilda_idtf.rs b/nannou_laser/src/ilda_idtf.rs index 4875cdf4b..c3b621d4f 100644 --- a/nannou_laser/src/ilda_idtf.rs +++ b/nannou_laser/src/ilda_idtf.rs @@ -52,10 +52,10 @@ where self.points.clear(); loop { let FrameReader { - ref mut reader, - ref mut points, - ref mut palette, - } = *self; + reader, + points, + palette, + } = self; // Read the next section. let section = match reader.read_next()? { diff --git a/scripts/set_version/main.rs b/scripts/set_version/main.rs index b32f38dba..779c9baad 100644 --- a/scripts/set_version/main.rs +++ b/scripts/set_version/main.rs @@ -103,12 +103,12 @@ fn update_dependencies_table(table: &mut toml_edit::Table, desired_version: &sem .entry(&dep) .as_value_mut() .expect("failed to retrieve toml value for dependency"); - let version_value = match *value { + let version_value = match value { toml_edit::Value::String(_) => value, - toml_edit::Value::InlineTable(ref mut inline_table) => { + toml_edit::Value::InlineTable(inline_table) => { inline_table.get_or_insert("version", "") } - ref v => panic!("unexpected dependency value: {:?}", v), + v => panic!("unexpected dependency value: {:?}", v), }; *version_value = format!("{}", desired_version).into(); }