Skip to content

Commit 5d2048a

Browse files
committed
make clippy happy
1 parent 75685d0 commit 5d2048a

File tree

13 files changed

+42
-48
lines changed

13 files changed

+42
-48
lines changed

src/chart/beat.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ impl Beat {
2525
pub const ONE: Self = Beat(1, Rational32::ZERO);
2626
}
2727

28-
impl Into<f32> for Beat {
29-
fn into(self) -> f32 {
30-
self.0 as f32 + *self.1.numer() as f32 / *self.1.denom() as f32
28+
impl From<Beat> for f32 {
29+
fn from(val: Beat) -> Self {
30+
val.0 as f32 + *val.1.numer() as f32 / *val.1.denom() as f32
3131
}
3232
}
3333

34-
impl Into<Rational32> for Beat {
35-
fn into(self) -> Rational32 {
36-
Rational32::new(self.0 * self.1.denom() + self.1.numer(), self.denom())
34+
impl From<Beat> for Rational32 {
35+
fn from(val: Beat) -> Self {
36+
Rational32::new(val.0 * val.1.denom() + val.1.numer(), val.denom())
3737
}
3838
}
3939

@@ -96,16 +96,16 @@ impl PartialEq for Beat {
9696
impl Eq for Beat {}
9797

9898
impl PartialOrd for Beat {
99-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
100-
match self.0.partial_cmp(&other.0) {
101-
Some(core::cmp::Ordering::Equal) => self.1.partial_cmp(&other.1),
102-
ord => ord,
103-
}
99+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
100+
Some(self.cmp(other))
104101
}
105102
}
106103

107104
impl Ord for Beat {
108105
fn cmp(&self, other: &Self) -> Ordering {
109-
self.partial_cmp(other).unwrap()
106+
match self.0.cmp(&other.0) {
107+
Ordering::Equal => self.1.cmp(&other.1),
108+
ord => ord,
109+
}
110110
}
111111
}

src/chart/note.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ pub struct Note {
2121

2222
impl Note {
2323
pub fn new(kind: NoteKind, above: bool, beat: Beat, x: f32) -> Self {
24-
return Self {
24+
Self {
2525
kind,
2626
above,
2727
beat,
2828
x,
29-
};
29+
}
3030
}
3131
}
3232

src/editing/create_note.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
timing::BpmList,
1212
};
1313

14+
#[allow(clippy::too_many_arguments)]
1415
pub fn create_note_system(
1516
mut commands: Commands,
1617
timeline: Timeline,

src/exporter/phichain.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ impl Exporter for PhiChainExporter {
2525
let mut events: Vec<LineEvent> = vec![];
2626
for child in children.iter() {
2727
if let Ok(note) = note_query.get(world, *child) {
28-
notes.push(note.clone());
28+
notes.push(*note);
2929
} else if let Ok(event) = event_query.get(world, *child) {
30-
events.push(event.clone());
30+
events.push(*event);
3131
}
3232
}
3333
chart.lines.push(LineWrapper(notes, events));

src/home.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn handle_select_illustration_system(
132132
if !matches!(kind, PickingKind::SelectIllustration) {
133133
continue;
134134
}
135-
form.illustration = path.clone();
135+
form.illustration.clone_from(path);
136136
}
137137
}
138138

@@ -144,7 +144,7 @@ fn handle_select_music_system(
144144
if !matches!(kind, PickingKind::SelectMusic) {
145145
continue;
146146
}
147-
form.music = path.clone();
147+
form.music.clone_from(path);
148148
}
149149
}
150150

src/loader/official.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl Loader for OfficialLoader {
138138
kind,
139139
above,
140140
t(note.time),
141-
note.x / 18.0 * CANVAS_WIDTH as f32,
141+
note.x / 18.0 * CANVAS_WIDTH,
142142
)))
143143
.id();
144144
note_ids.push(note_id);
@@ -197,9 +197,8 @@ impl Loader for OfficialLoader {
197197
})
198198
.id();
199199

200-
match first_line_id {
201-
None => first_line_id = Some(id),
202-
_ => {}
200+
if first_line_id.is_none() {
201+
first_line_id = Some(id)
203202
}
204203
}
205204
commands.insert_resource(SelectedLine(first_line_id.unwrap()));

src/loader/phichain.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ impl Loader for PhiChainLoader {
3131
})
3232
.id();
3333

34-
match first_line_id {
35-
None => first_line_id = Some(id),
36-
_ => {}
34+
if first_line_id.is_none() {
35+
first_line_id = Some(id)
3736
}
3837
}
3938

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn main() {
7171
.add_plugins(MiscPlugin)
7272
.add_plugins(TabPlugin)
7373
.add_plugins(EditingPlugin)
74-
.add_plugins(FrameTimeDiagnosticsPlugin::default())
74+
.add_plugins(FrameTimeDiagnosticsPlugin)
7575
.add_plugins(AssetsPlugin)
7676
.add_plugins(TranslationPlugin)
7777
.add_plugins(NotificationPlugin)

src/tab/game/core.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ struct SpeedEvent {
242242

243243
impl SpeedEvent {
244244
fn new(start_time: f32, end_time: f32, start_value: f32, end_value: f32) -> Self {
245-
return Self {
245+
Self {
246246
start_time,
247247
end_time,
248248
start_value,
249249
end_value,
250-
};
250+
}
251251
}
252252
}
253253

@@ -257,16 +257,13 @@ fn calculate_speed_events_system(
257257
bpm_list: Res<BpmList>,
258258
) {
259259
for (event, entity) in &query {
260-
match event.kind {
261-
LineEventKind::Speed => {
262-
commands.entity(entity).insert(SpeedEvent::new(
263-
bpm_list.time_at(event.start_beat),
264-
bpm_list.time_at(event.end_beat),
265-
event.start,
266-
event.end,
267-
));
268-
}
269-
_ => {}
260+
if let LineEventKind::Speed = event.kind {
261+
commands.entity(entity).insert(SpeedEvent::new(
262+
bpm_list.time_at(event.start_beat),
263+
bpm_list.time_at(event.end_beat),
264+
event.start,
265+
event.end,
266+
));
270267
}
271268
}
272269
}

src/tab/game/ui.rs

-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ fn setup_combo_ui_system(mut commands: Commands, asset_server: Res<AssetServer>)
8585
font: asset_server.load("font/phigros.ttf"),
8686
font_size: 20.0,
8787
color: Color::WHITE,
88-
..default()
8988
},
9089
),
9190
..default()
@@ -101,7 +100,6 @@ fn setup_combo_ui_system(mut commands: Commands, asset_server: Res<AssetServer>)
101100
font: asset_server.load("font/phigros.ttf"),
102101
font_size: 10.0,
103102
color: Color::WHITE,
104-
..default()
105103
},
106104
),
107105
..default()
@@ -138,7 +136,6 @@ fn spawn_score_ui_system(mut commands: Commands, asset_server: Res<AssetServer>)
138136
font: asset_server.load("font/phigros.ttf"),
139137
font_size: 10.0,
140138
color: Color::WHITE,
141-
..default()
142139
},
143140
),
144141
..default()

src/tab/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl TabRegistry {
3333
if let Some(tab) = self.0.get_mut(tab) {
3434
tab.run(world, ui);
3535
} else {
36-
ui.colored_label(egui::Color32::RED, format!("Tab does not exist."));
36+
ui.colored_label(egui::Color32::RED, "Tab does not exist.".to_string());
3737
}
3838
}
3939
}

src/tab/timeline.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl Plugin for TimelineTabPlugin {
2424
}
2525
}
2626

27+
#[allow(clippy::too_many_arguments)]
2728
pub fn timeline_ui_system(
2829
In(ui): In<&mut Ui>,
2930
selected_line_query: Res<SelectedLine>,

src/translation.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ impl Plugin for TranslationPlugin {
1212
}
1313

1414
fn load_translations(mut storage: ResMut<TranslationStorage>) {
15-
let file = std::fs::File::open("lang/meta/languages.json")
16-
.expect(&format!("Failed to load translations"));
15+
let file =
16+
std::fs::File::open("lang/meta/languages.json").expect("Failed to load translations");
1717
let languages: Vec<String> =
18-
serde_json::from_reader(file).expect(&format!("Failed to load translations"));
18+
serde_json::from_reader(file).expect("Failed to load translations");
1919

2020
for language in languages {
2121
let mapping = load_translation(&language);
@@ -52,9 +52,9 @@ fn flatten(prefix: Option<&str>, value: &Value, result: &mut HashMap<String, Str
5252

5353
fn load_translation(lang: &String) -> HashMap<String, String> {
5454
let file = std::fs::File::open(format!("lang/{}.yml", lang))
55-
.expect(&format!("Failed to load translation: {}", lang));
56-
let value: Value =
57-
serde_yaml::from_reader(file).expect(&format!("Failed to load translation: {}", lang));
55+
.unwrap_or_else(|_| panic!("Failed to load translation: {}", lang));
56+
let value: Value = serde_yaml::from_reader(file)
57+
.unwrap_or_else(|_| panic!("Failed to load translation: {}", lang));
5858

5959
let mut mapping: HashMap<String, String> = HashMap::new();
6060
flatten(None, &value, &mut mapping);

0 commit comments

Comments
 (0)