Skip to content

Commit

Permalink
Refac unnecessary ref mut pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Nov 19, 2023
1 parent e375ea7 commit 193e729
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 51 deletions.
14 changes: 8 additions & 6 deletions examples/draw/draw_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/laser/laser_frame_stream_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions examples/ui/egui/circle_packing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
});
Expand Down
8 changes: 4 additions & 4 deletions examples/ui/egui/tune_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion generative_design/shape/p_2_1_5_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions nannou/src/draw/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions nannou/src/draw/primitive/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
..
},
..
Expand Down
4 changes: 2 additions & 2 deletions nannou/src/draw/properties/spatial/orientation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`"),
}
Expand Down
2 changes: 1 addition & 1 deletion nannou/src/text/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ContourPathEvents {
impl<'a, 'b> Iterator for Rects<'a, 'b> {
type Item = (ScaledGlyph<'a>, Rect);
fn next(&mut self) -> Option<Self::Item> {
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
Expand Down
8 changes: 4 additions & 4 deletions nannou_audio/src/requester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ where
FR: stream::output::RenderFn<M, S>,
{
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() {
Expand Down
2 changes: 1 addition & 1 deletion nannou_audio/src/stream/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<M, FC, FE, S> Builder<M, FC, FE, S> {
// 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion nannou_audio/src/stream/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<M, FR, FE, S> Builder<M, FR, FE, S> {
// 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);
}
}
Expand Down
5 changes: 1 addition & 4 deletions nannou_core/src/geom/ellipse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ where
{
type Item = Tri<[S; 2]>;
fn next(&mut self) -> Option<Self::Item> {
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;
Expand Down
6 changes: 3 additions & 3 deletions nannou_egui_demo_app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion nannou_isf/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions nannou_laser/src/ilda_idtf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()? {
Expand Down
6 changes: 3 additions & 3 deletions scripts/set_version/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 193e729

Please sign in to comment.