Skip to content

Commit a9b9e0c

Browse files
committed
Turn More Functions Into const fn Functions
Clippy now suggests that we should turn more functions into `const fn` functions, so this is what we do here. It seems like it can't reason about `Deref` and thus thinks more functions can be `const fn` than what is actually possible.
1 parent f9dcff8 commit a9b9e0c

File tree

31 files changed

+98
-89
lines changed

31 files changed

+98
-89
lines changed

capi/bind_gen/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ mod wasm_bindgen;
1515
use clap::Parser;
1616
use std::{
1717
collections::BTreeMap,
18-
fs::{self, create_dir_all, remove_dir_all, File},
18+
fs::{self, File, create_dir_all, remove_dir_all},
1919
io::{BufWriter, Read, Result},
2020
path::PathBuf,
2121
rc::Rc,
2222
};
2323
use syn::{
24-
parse_file, Expr, ExprLit, FnArg, Item, ItemFn, Lit, Meta, MetaList, Pat, ReturnType,
25-
Signature, Type as SynType, Visibility,
24+
Expr, ExprLit, FnArg, Item, ItemFn, Lit, Meta, MetaList, Pat, ReturnType, Signature,
25+
Type as SynType, Visibility, parse_file,
2626
};
2727

2828
#[derive(clap::Parser)]
@@ -106,7 +106,7 @@ fn get_type(ty: &SynType) -> Type {
106106
ty
107107
}
108108
SynType::Path(path) => {
109-
let segment = path.path.segments.iter().last().expect("Weird path");
109+
let segment = path.path.segments.iter().next_back().expect("Weird path");
110110
let mut name = segment.ident.to_string();
111111
let is_nullable = if let Some(rest) = name.strip_prefix("Nullable") {
112112
name = rest.to_string();

src/analysis/state_helper.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Provides different helper functions.
22
33
use crate::{
4-
comparison::best_segments, settings::SemanticColor, timing::Snapshot, Run, Segment, TimeSpan,
5-
Timer, TimerPhase, TimingMethod,
4+
Run, Segment, TimeSpan, Timer, TimerPhase, TimingMethod, comparison::best_segments,
5+
settings::SemanticColor, timing::Snapshot,
66
};
77

88
/// Gets the last non-live delta in the [`Run`] starting from `segment_index`.
@@ -254,7 +254,7 @@ pub fn live_segment_delta(
254254
///
255255
/// - `timer`: The current [`Timer`].
256256
/// - `split_delta`: Specifies whether to return a split delta rather than a
257-
/// segment delta and to start showing the live segment once you are behind.
257+
/// segment delta and to start showing the live segment once you are behind.
258258
/// - `comparison`: The comparison that you are comparing with.
259259
/// - `method`: The [`TimingMethod`] that you are using.
260260
///
@@ -300,7 +300,7 @@ pub fn check_live_delta(
300300
/// - `time_difference`: The delta that you want to find a color for.
301301
/// - `segment_index`: The split number that is associated with this delta.
302302
/// - `show_segment_deltas`: Can show ahead gaining and behind losing colors if
303-
/// true.
303+
/// true.
304304
/// - `show_best_segments`: Can show the best segment color if true.
305305
/// - `comparison`: The comparison that you are comparing this delta to.
306306
/// - `method`: The [`TimingMethod`] of this delta.

src/component/blank_space.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Component {
7373
}
7474

7575
/// Grants mutable access to the settings of the component.
76-
pub fn settings_mut(&mut self) -> &mut Settings {
76+
pub const fn settings_mut(&mut self) -> &mut Settings {
7777
&mut self.settings
7878
}
7979

@@ -83,7 +83,7 @@ impl Component {
8383
}
8484

8585
/// Updates the component's state.
86-
pub fn update_state(&self, state: &mut State) {
86+
pub const fn update_state(&self, state: &mut State) {
8787
state.background = self.settings.background;
8888
state.size = self.settings.size;
8989
}

src/component/current_comparison.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
55
use super::key_value;
66
use crate::{
7+
Timer,
78
platform::prelude::*,
89
settings::{Color, Field, Gradient, SettingsDescription, Value},
9-
Timer,
1010
};
1111
use serde_derive::{Deserialize, Serialize};
1212

@@ -62,7 +62,7 @@ impl Component {
6262
}
6363

6464
/// Grants mutable access to the settings of the component.
65-
pub fn settings_mut(&mut self) -> &mut Settings {
65+
pub const fn settings_mut(&mut self) -> &mut Settings {
6666
&mut self.settings
6767
}
6868

src/component/current_pace.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
66
use super::key_value;
77
use crate::{
8+
TimerPhase,
89
analysis::current_pace,
910
comparison,
1011
platform::prelude::*,
1112
settings::{Color, Field, Gradient, SettingsDescription, Value},
1213
timing::{
13-
formatter::{Accuracy, Regular, TimeFormatter},
1414
Snapshot,
15+
formatter::{Accuracy, Regular, TimeFormatter},
1516
},
16-
TimerPhase,
1717
};
1818
use alloc::borrow::Cow;
1919
use core::fmt::Write;
@@ -79,7 +79,7 @@ impl Component {
7979
}
8080

8181
/// Grants mutable access to the settings of the component.
82-
pub fn settings_mut(&mut self) -> &mut Settings {
82+
pub const fn settings_mut(&mut self) -> &mut Settings {
8383
&mut self.settings
8484
}
8585

src/component/delta/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
55
use super::key_value;
66
use crate::{
7+
GeneralLayoutSettings,
78
analysis::{delta, state_helper},
89
comparison,
910
platform::prelude::*,
1011
settings::{Color, Field, Gradient, SemanticColor, SettingsDescription, Value},
1112
timing::{
12-
formatter::{Accuracy, Delta, TimeFormatter},
1313
Snapshot,
14+
formatter::{Accuracy, Delta, TimeFormatter},
1415
},
15-
GeneralLayoutSettings,
1616
};
1717
use alloc::borrow::Cow;
1818
use core::fmt::Write;
@@ -80,7 +80,7 @@ impl Component {
8080
}
8181

8282
/// Grants mutable access to the settings of the component.
83-
pub fn settings_mut(&mut self) -> &mut Settings {
83+
pub const fn settings_mut(&mut self) -> &mut Settings {
8484
&mut self.settings
8585
}
8686

src/component/graph.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
// edge. "Content" is the rest (the area inside).
1212

1313
use crate::{
14-
analysis, comparison,
14+
GeneralLayoutSettings, TimeSpan, Timer, TimerPhase, analysis, comparison,
1515
platform::prelude::*,
1616
settings::{Color, Field, SettingsDescription, Value},
1717
timing::Snapshot,
18-
GeneralLayoutSettings, TimeSpan, Timer, TimerPhase,
1918
};
2019
use alloc::borrow::Cow;
2120
use serde_derive::{Deserialize, Serialize};
@@ -206,7 +205,7 @@ impl Component {
206205
}
207206

208207
/// Grants mutable access to the settings of the component.
209-
pub fn settings_mut(&mut self) -> &mut Settings {
208+
pub const fn settings_mut(&mut self) -> &mut Settings {
210209
&mut self.settings
211210
}
212211

@@ -388,7 +387,7 @@ impl Component {
388387
Some(x_axis)
389388
}
390389

391-
fn copy_settings_to_state(&self, state: &mut State) {
390+
const fn copy_settings_to_state(&self, state: &mut State) {
392391
let settings = &self.settings;
393392
(state.top_background_color, state.bottom_background_color) = if settings.flip_graph {
394393
(

src/component/pb_chance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Component {
6868
}
6969

7070
/// Grants mutable access to the settings of the component.
71-
pub fn settings_mut(&mut self) -> &mut Settings {
71+
pub const fn settings_mut(&mut self) -> &mut Settings {
7272
&mut self.settings
7373
}
7474

src/component/possible_time_save.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
77
use super::key_value;
88
use crate::{
9+
TimerPhase,
910
analysis::possible_time_save,
1011
comparison,
1112
platform::prelude::*,
1213
settings::{Color, Field, Gradient, SettingsDescription, Value},
1314
timing::{
14-
formatter::{Accuracy, SegmentTime, TimeFormatter},
1515
Snapshot,
16+
formatter::{Accuracy, SegmentTime, TimeFormatter},
1617
},
17-
TimerPhase,
1818
};
1919
use alloc::borrow::Cow;
2020
use core::fmt::Write as FmtWrite;
@@ -86,7 +86,7 @@ impl Component {
8686
}
8787

8888
/// Grants mutable access to the settings of the component.
89-
pub fn settings_mut(&mut self) -> &mut Settings {
89+
pub const fn settings_mut(&mut self) -> &mut Settings {
9090
&mut self.settings
9191
}
9292

src/component/previous_segment.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
99
use super::key_value;
1010
use crate::{
11-
analysis, comparison,
11+
GeneralLayoutSettings, TimerPhase, analysis, comparison,
1212
platform::prelude::*,
1313
settings::{Color, Field, Gradient, SemanticColor, SettingsDescription, Value},
1414
timing::{
15-
formatter::{Accuracy, Delta, SegmentTime, TimeFormatter},
1615
Snapshot,
16+
formatter::{Accuracy, Delta, SegmentTime, TimeFormatter},
1717
},
18-
GeneralLayoutSettings, TimerPhase,
1918
};
2019
use alloc::borrow::Cow;
2120
use core::fmt::Write as FmtWrite;
@@ -88,7 +87,7 @@ impl Component {
8887
}
8988

9089
/// Grants mutable access to the settings of the component.
91-
pub fn settings_mut(&mut self) -> &mut Settings {
90+
pub const fn settings_mut(&mut self) -> &mut Settings {
9291
&mut self.settings
9392
}
9493

src/component/segment_time/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
66
use super::key_value;
77
use crate::{
8+
Timer, TimerPhase,
89
analysis::state_helper::comparison_single_segment_time,
910
comparison,
1011
platform::prelude::*,
1112
settings::{Color, Field, Gradient, SettingsDescription, Value},
1213
timing::formatter::{Accuracy, SegmentTime, TimeFormatter},
13-
Timer, TimerPhase,
1414
};
1515
use alloc::borrow::Cow;
1616
use core::fmt::Write;
@@ -79,7 +79,7 @@ impl Component {
7979
}
8080

8181
/// Grants mutable access to the settings of the component.
82-
pub fn settings_mut(&mut self) -> &mut Settings {
82+
pub const fn settings_mut(&mut self) -> &mut Settings {
8383
&mut self.settings
8484
}
8585

src/component/separator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Component {
3838
}
3939

4040
/// Updates the component's state.
41-
pub fn update_state(&self, _state: &mut State) {}
41+
pub const fn update_state(&self, _state: &mut State) {}
4242

4343
/// Calculates the component's state.
4444
pub const fn state(&self) -> State {

src/component/splits/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
//! [`Segment`](crate::run::Segment) needs to be shown all the time.
77
88
use crate::{
9+
GeneralLayoutSettings,
910
platform::prelude::*,
1011
settings::{
1112
self, Color, Field, Gradient, ImageCache, ImageId, ListGradient, SettingsDescription, Value,
1213
},
13-
timing::{formatter::Accuracy, Snapshot},
14+
timing::{Snapshot, formatter::Accuracy},
1415
util::{Clear, ClearVec},
15-
GeneralLayoutSettings,
1616
};
1717
use core::cmp::{max, min};
1818
use serde_derive::{Deserialize, Serialize};
@@ -242,19 +242,19 @@ impl Component {
242242
}
243243

244244
/// Grants mutable access to the settings of the component.
245-
pub fn settings_mut(&mut self) -> &mut Settings {
245+
pub const fn settings_mut(&mut self) -> &mut Settings {
246246
&mut self.settings
247247
}
248248

249249
/// Scrolls up the window of the segments that are shown. Doesn't move the
250250
/// scroll window if it reaches the top of the segments.
251-
pub fn scroll_up(&mut self) {
251+
pub const fn scroll_up(&mut self) {
252252
self.scroll_offset = self.scroll_offset.saturating_sub(1);
253253
}
254254

255255
/// Scrolls down the window of the segments that are shown. Doesn't move the
256256
/// scroll window if it reaches the bottom of the segments.
257-
pub fn scroll_down(&mut self) {
257+
pub const fn scroll_down(&mut self) {
258258
self.scroll_offset = self.scroll_offset.saturating_add(1);
259259
}
260260

src/component/sum_of_best.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
1010
use super::key_value;
1111
use crate::{
12+
Timer,
1213
analysis::sum_of_segments::calculate_best,
1314
platform::prelude::*,
1415
settings::{Color, Field, Gradient, SettingsDescription, Value},
1516
timing::formatter::{Accuracy, Regular, TimeFormatter},
16-
Timer,
1717
};
1818
use core::fmt::Write;
1919
use serde_derive::{Deserialize, Serialize};
@@ -78,7 +78,7 @@ impl Component {
7878
}
7979

8080
/// Grants mutable access to the settings of the component.
81-
pub fn settings_mut(&mut self) -> &mut Settings {
81+
pub const fn settings_mut(&mut self) -> &mut Settings {
8282
&mut self.settings
8383
}
8484

src/component/text/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
66
use super::key_value;
77
use crate::{
8+
Timer,
89
platform::prelude::*,
910
settings::{Color, Field, Gradient, SettingsDescription, Value},
1011
timing::formatter,
1112
util::PopulateString,
12-
Timer,
1313
};
1414
use alloc::borrow::Cow;
1515
use core::mem;
@@ -178,7 +178,7 @@ impl Component {
178178
}
179179

180180
/// Grants mutable access to the settings of the component.
181-
pub fn settings_mut(&mut self) -> &mut Settings {
181+
pub const fn settings_mut(&mut self) -> &mut Settings {
182182
&mut self.settings
183183
}
184184

src/component/timer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
//! current attempt is doing compared to the chosen comparison.
55
66
use crate::{
7+
GeneralLayoutSettings, TimeSpan, TimerPhase, TimingMethod,
78
analysis::split_color,
89
platform::prelude::*,
910
settings::{Color, Field, Gradient, SemanticColor, SettingsDescription, Value},
1011
timing::{
11-
formatter::{timer as formatter, Accuracy, DigitsFormat, TimeFormatter},
1212
Snapshot,
13+
formatter::{Accuracy, DigitsFormat, TimeFormatter, timer as formatter},
1314
},
14-
GeneralLayoutSettings, TimeSpan, TimerPhase, TimingMethod,
1515
};
1616
use core::fmt::Write;
1717
use serde_derive::{Deserialize, Serialize};
@@ -174,7 +174,7 @@ impl Component {
174174
}
175175

176176
/// Grants mutable access to the settings of the component.
177-
pub fn settings_mut(&mut self) -> &mut Settings {
177+
pub const fn settings_mut(&mut self) -> &mut Settings {
178178
&mut self.settings
179179
}
180180

0 commit comments

Comments
 (0)