Skip to content

Commit

Permalink
fix: resolved some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
CalliEve committed Nov 21, 2024
1 parent b69944c commit bd4fd02
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/algorithm/cost_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn diagonal_occupied(
return map
.get_station(station_id)
.zip(diag_two.get_edge_id())
.map_or(false, |(s, edge_id)| {
.is_some_and(|(s, edge_id)| {
s.get_edges()
.contains(&edge_id)
});
Expand All @@ -276,7 +276,7 @@ fn diagonal_occupied(
return map
.get_station(station_id)
.zip(diag_one.get_edge_id())
.map_or(false, |(s, edge_id)| {
.is_some_and(|(s, edge_id)| {
s.get_edges()
.contains(&edge_id)
});
Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/drawing/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ pub fn draw_grid(canvas: &CanvasContext, state: CanvasState) {
canvas,
height,
drawn_square_size,
f64::from(width) / drawn_square_size,
width / drawn_square_size,
);
draw_horizontal_lines(
canvas,
width,
drawn_square_size,
f64::from(height) / drawn_square_size,
height / drawn_square_size,
);

canvas.stroke();
Expand Down
7 changes: 4 additions & 3 deletions src/components/atoms/canvas_info_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use wasm_bindgen::JsCast;
use crate::MapState;

/// A generic canvas info box that others can be based upon.
#[allow(clippy::needless_pass_by_value)] // cannot be a reference because of the `Fn` trait
#[component]
pub fn CanvasInfoBox<S, C>(
/// The title of the info box,
Expand All @@ -20,7 +21,7 @@ pub fn CanvasInfoBox<S, C>(
children: Option<Children>,
) -> impl IntoView
where
S: ToString,
S: ToString + 'static,
C: Fn() + 'static,
{
let info_box_ref: NodeRef<html::Div> = create_node_ref();
Expand Down Expand Up @@ -65,7 +66,7 @@ where

// Offset by 15px to the left, aka 1rem - 1px
let screen_pos = map_pos + sidebar_width + 2.0;
format!("{}px", screen_pos)
format!("{screen_pos}px")
};
let top = move || {
let map_pos = click_position
Expand All @@ -79,7 +80,7 @@ where

// Offset by 15px to the top, aka 1rem - 1px
let screen_pos = map_pos + navbar_height + 2.0;
format!("{}px", screen_pos)
format!("{screen_pos}px")
};

view! {
Expand Down
8 changes: 4 additions & 4 deletions src/components/atoms/text_with_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
F: Fn(String) + Copy + 'static,
{
let (editing, set_editing) = create_signal(false);
let (text_input, set_text_input) = create_signal("".to_string());
let (text_input, set_text_input) = create_signal(String::new());

// Generate the id for the input element and label.
let edit_label_for_id = edit_label.clone();
Expand All @@ -50,13 +50,13 @@ where
let on_done = move |_| {
set_editing(false);
on_edit(text_input.get());
set_text_input("".to_string());
set_text_input(String::new());
};
let on_submit = move |ev: KeyboardEvent| {
if ev.key() == "Enter" {
set_editing(false);
on_edit(text_input.get());
set_text_input("".to_string());
set_text_input(String::new());
}
};

Expand Down Expand Up @@ -115,7 +115,7 @@ where
class="pointer-events-none absolute left-3 top-0 mb-0 max-w-[90%] origin-[0_0] truncate pt-[0.37rem] leading-[1.6] text-neutral-500 peer-focus:text-primary -translate-y-[0.9rem] scale-[0.8] dark:text-neutral-400 dark:peer-focus:text-primary"
>{edit_label.clone()}
</label>
<Button text="finish editing" smaller=true on_click=Box::new(on_done.clone())>
<Button text="finish editing" smaller=true on_click=Box::new(on_done)>
"done"
</Button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/toggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
id={id.clone()}
_ref=input_ref
on:input=parse_input
checked=move || value.map_or(false, |v| v())
checked=move || value.is_some_and(|v| v())
prop:value=move || value.map(|v| v()) />
<span
class="pointer-events-none inline-block align-middle p-2 truncate pt-[0.37rem] text-neutral-500 peer-focus:text-primary dark:text-neutral-400 dark:peer-focus:text-primary"
Expand Down
6 changes: 2 additions & 4 deletions src/components/canvas/dbl_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ pub fn on_dbl_click(map_state: &mut MapState, ev: &UiEvent, shift_key: bool) {
.chain(
map_state
.get_selected_stations()
.to_vec()
.into_iter(),
.to_vec(),
)
.sorted_by_key(|s| {
s.get_station()
Expand All @@ -82,8 +81,7 @@ pub fn on_dbl_click(map_state: &mut MapState, ev: &UiEvent, shift_key: bool) {
.chain(
map_state
.get_selected_edges()
.to_vec()
.into_iter(),
.to_vec(),
)
.sorted()
.dedup()
Expand Down
10 changes: 5 additions & 5 deletions src/components/canvas/mouse_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ pub fn on_mouse_up(map_state: &mut MapState, ev: &UiEvent, shift_key: bool) {
map_state.clear_selected_line();

if let Some(grabbed_at) = selected_line.get_grabbed_at() {
if grabbed_at != mouse_pos {
map_state.clear_all_selections();
return;
} else {
if grabbed_at == mouse_pos {
// Handle a single click on an edge
if edge_at_node.is_some()
&& !shift_key
Expand All @@ -131,7 +128,7 @@ pub fn on_mouse_up(map_state: &mut MapState, ev: &UiEvent, shift_key: bool) {
let selected_edge_id = map_state
.get_selected_edges()
.first()
.cloned()
.copied()
.unwrap();

let selected_edge = map
Expand All @@ -143,6 +140,9 @@ pub fn on_mouse_up(map_state: &mut MapState, ev: &UiEvent, shift_key: bool) {
map_state.set_clicked_on_edge(selected_edge, canvas_pos);
return;
}
} else {
map_state.clear_all_selections();
return;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/canvas/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn update_canvas_size(map_state: &RwSignal<MapState>) {
state.update_canvas_state(|canvas| {
canvas.set_size((height, width));
canvas.set_neighbor_sizes((nav_height, side_width));
})
});
});
}

Expand Down
13 changes: 8 additions & 5 deletions src/components/molecules/edge_info_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ use crate::{
};

#[component]
fn LineInfo(line: Line, i: usize) -> impl IntoView {
fn LineInfo(
/// The line to show information about.
line: Line,
/// The index of the line in the list of lines.
i: usize,
) -> impl IntoView {
let map_state =
use_context::<RwSignal<MapState>>().expect("to have found the global map state");
let (line, set_line) = create_signal(line);
Expand Down Expand Up @@ -78,9 +83,7 @@ fn LineInfo(line: Line, i: usize) -> impl IntoView {
if i > 0 {view!{
<hr class="my-0.5"/>
}.into_view()} else {
view!{
<></>
}.into_view()}
view!{}.into_view()}
}
<p class="text-md font-semibold"><b>"Name:\n"</b>
<TextWithEdit
Expand Down Expand Up @@ -124,7 +127,7 @@ pub fn EdgeInfoBox() -> impl IntoView {
.get_clicked_on_edge()
.map_or(Vec::new(), |e| {
e.get_lines()
.into_iter()
.iter()
.map(|l| {
state
.get_map()
Expand Down
8 changes: 2 additions & 6 deletions src/components/molecules/file_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@ where
let file_name = file.name();
let file_ext = Path::new(&file_name).extension();

let file_type = if file_ext.map_or(false, |ext| {
ext.eq_ignore_ascii_case("json")
}) {
let file_type = if file_ext.is_some_and(|ext| ext.eq_ignore_ascii_case("json")) {
FileType::Json
} else if file_ext.map_or(false, |ext| {
ext.eq_ignore_ascii_case("graphml")
}) {
} else if file_ext.is_some_and(|ext| ext.eq_ignore_ascii_case("graphml")) {
FileType::GraphML
} else {
return;
Expand Down
9 changes: 6 additions & 3 deletions src/components/molecules/station_info_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use crate::{
CanvasInfoBox,
TextWithEdit,
},
models::StationID,
models::{
Station,
StationID,
},
MapState,
};

Expand Down Expand Up @@ -40,7 +43,7 @@ pub fn StationInfoBox() -> impl IntoView {
map_state
.get()
.get_clicked_on_station()
.map_or("".to_string(), |s| {
.map_or(String::new(), |s| {
logging::log!(
"Name of station: {}: {}",
s.get_id(),
Expand All @@ -60,7 +63,7 @@ pub fn StationInfoBox() -> impl IntoView {
map_state
.get()
.get_clicked_on_station()
.map(|s| s.get_id())
.map(Station::get_id)
};

let edit_station_name = move |station_id_opt: Option<StationID>, new_name: String| {
Expand Down
2 changes: 2 additions & 0 deletions src/components/organisms/canvas_controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Async is used for futures, which are used in the worker, even though the algorithm itself is
// sync.
#![allow(clippy::unused_async)]
// This otherwise gets triggered by one in the wasm worker.
#![allow(unexpected_cfgs)]

use ev::KeyboardEvent;
use html::Div;
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn Sidebar() -> impl IntoView {
<Button
on_click=Box::new(move |_| map_state.update(|state| {
state.clear_all_selections();
state.set_map(state.get_last_loaded().cloned().unwrap_or_else(testmap))
state.set_map(state.get_last_loaded().cloned().unwrap_or_else(testmap));
}))
text="reset map" />
<ButtonGroup
Expand Down
16 changes: 8 additions & 8 deletions src/components/state/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ impl CanvasState {
/// Recalculates the maximum and minimum values for the x and y coordinates
/// to fit on the canvas.
fn recalculate_limits(&mut self) {
let width_node_count = (f64::from(
self.size
.1,
) / self.drawn_square_size())
let width_node_count = (self
.size
.1
/ self.drawn_square_size())
.round() as i32;
let height_node_count = (f64::from(
self.size
.0,
) / self.drawn_square_size())
let height_node_count = (self
.size
.0
/ self.drawn_square_size())
.round() as i32;

self.x_limit = (
Expand Down

0 comments on commit bd4fd02

Please sign in to comment.