Skip to content

Commit 412231e

Browse files
committed
chore: cargo clippy
1 parent 30c515d commit 412231e

File tree

8 files changed

+46
-71
lines changed

8 files changed

+46
-71
lines changed

src/database/src/database.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use crate::{
3333
sql_structs, util,
3434
};
3535

36+
#[derive(Default)]
3637
pub struct Database {
3738
database: Option<Connection>,
3839
pub path: Option<String>,
@@ -51,10 +52,7 @@ impl Error for NoDatabaseOpen {}
5152

5253
impl Database {
5354
pub fn new() -> Self {
54-
Database {
55-
database: None,
56-
path: None,
57-
}
55+
Default::default()
5856
}
5957

6058
fn get_database(&self) -> Result<&Connection, NoDatabaseOpen> {

src/database/src/output/airspace.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Path {
6262
arc: None,
6363
path_type: match boundary_char {
6464
'G' => PathType::GreatCircle,
65-
'H' | _ => PathType::RhumbLine,
65+
_ => PathType::RhumbLine,
6666
},
6767
},
6868
'L' | 'R' => Self {
@@ -79,7 +79,7 @@ impl Path {
7979
bearing: arc_bearing.unwrap(),
8080
direction: match boundary_char {
8181
'R' => TurnDirection::Right,
82-
'L' | _ => TurnDirection::Left,
82+
_ => TurnDirection::Left,
8383
},
8484
}),
8585
path_type: PathType::Arc,
@@ -115,7 +115,7 @@ pub(crate) fn map_controlled_airspaces(
115115
let mut airspace_complete = false;
116116

117117
data.into_iter().fold(Vec::new(), |mut airspaces, row| {
118-
if airspaces.len() == 0 || airspace_complete {
118+
if airspaces.is_empty() || airspace_complete {
119119
airspaces.push(ControlledAirspace {
120120
area_code: row.area_code.clone(),
121121
icao_code: row.icao_code.clone(),
@@ -124,7 +124,7 @@ pub(crate) fn map_controlled_airspaces(
124124
.controlled_airspace_name
125125
.clone()
126126
.expect("First row of an airspace data must have a name"),
127-
airspace_type: row.airspace_type.clone(),
127+
airspace_type: row.airspace_type,
128128
boundary_paths: Vec::new(),
129129
});
130130

@@ -157,7 +157,7 @@ pub(crate) fn map_restrictive_airspaces(
157157
let mut airspace_complete = false;
158158

159159
data.into_iter().fold(Vec::new(), |mut airspaces, row| {
160-
if airspaces.len() == 0 || airspace_complete {
160+
if airspaces.is_empty() || airspace_complete {
161161
airspaces.push(RestrictiveAirspace {
162162
area_code: row.area_code.clone(),
163163
icao_code: row.icao_code.clone(),
@@ -166,7 +166,7 @@ pub(crate) fn map_restrictive_airspaces(
166166
.restrictive_airspace_name
167167
.clone()
168168
.expect("First row of an airspace data must have a name"),
169-
airspace_type: row.restrictive_type.clone(),
169+
airspace_type: row.restrictive_type,
170170
boundary_paths: Vec::new(),
171171
});
172172

src/database/src/output/procedure/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn mut_find_or_insert<T, P: FnMut(&T) -> bool>(vec: &mut Vec<T>, condition: P, v
2626
}
2727

2828
/// Applies the neccesary logic for adding a leg with an enroute transition route type into a procedure
29-
pub(self) fn apply_enroute_transition_leg(
29+
fn apply_enroute_transition_leg(
3030
leg: ProcedureLeg,
3131
transition_identifier: String,
3232
enroute_transitions: &mut Vec<Transition>,
@@ -44,12 +44,12 @@ pub(self) fn apply_enroute_transition_leg(
4444
}
4545

4646
/// Applies the neccesary logic for adding a leg with a common leg route type into a procedure
47-
pub(self) fn apply_common_leg(
47+
fn apply_common_leg(
4848
leg: ProcedureLeg,
4949
transition_identifier: Option<String>,
5050
runway_transitions: &mut Vec<Transition>,
5151
common_legs: &mut Vec<ProcedureLeg>,
52-
runways: &Vec<Runways>,
52+
runways: &[Runways],
5353
) {
5454
// Common legs can still have a transition identifier, meaning that this procedure is only for
5555
// specific runways, but with the same legs for each runway.
@@ -113,11 +113,11 @@ pub(self) fn apply_common_leg(
113113
}
114114

115115
/// Applies the neccesary logic for adding a leg with a runway transition route type into a procedure
116-
pub(self) fn apply_runway_transition_leg(
116+
fn apply_runway_transition_leg(
117117
leg: ProcedureLeg,
118118
transition_identifier: String,
119119
runway_transitions: &mut Vec<Transition>,
120-
runways: &Vec<Runways>,
120+
runways: &[Runways],
121121
) {
122122
// If transition identifier ends in B, it means this transition serves all runways with the same
123123
// number. To make this easier to use in an FMS, we duplicate the transitions for all runways which

src/database/src/util.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ pub enum PathType {
1717
/// We aren't able to get file metadata in the sim so we can't use some of the standard library file system functions
1818
/// (like is_dir, exists, and some others)
1919
pub fn get_path_type(path: &Path) -> PathType {
20-
match fs::read_dir(path) {
21-
Ok(mut dir_res) => {
22-
let next = dir_res.next();
23-
24-
if let Some(result) = next {
25-
if result.is_ok() {
26-
return PathType::Directory;
27-
}
20+
if let Ok(mut dir_res) = fs::read_dir(path) {
21+
let next = dir_res.next();
22+
23+
if let Some(result) = next {
24+
if result.is_ok() {
25+
return PathType::Directory;
2826
}
2927
}
30-
Err(_) => {}
3128
};
3229

3330
let file_res = fs::File::open(path);
@@ -39,7 +36,7 @@ pub fn get_path_type(path: &Path) -> PathType {
3936
}
4037

4138
pub fn find_sqlite_file(path: &str) -> Result<String, Box<dyn Error>> {
42-
if get_path_type(&Path::new(path)) != PathType::Directory {
39+
if get_path_type(Path::new(path)) != PathType::Directory {
4340
return Err("Path is not a directory".into());
4441
}
4542

@@ -50,7 +47,7 @@ pub fn find_sqlite_file(path: &str) -> Result<String, Box<dyn Error>> {
5047
if get_path_type(&path) == PathType::File {
5148
let path = path.to_str().ok_or("Invalid path")?;
5249

53-
let extension = path.split(".").last();
50+
let extension = path.split('.').last();
5451

5552
if extension == Some("s3db") {
5653
return Ok(path.to_string());
@@ -61,7 +58,7 @@ pub fn find_sqlite_file(path: &str) -> Result<String, Box<dyn Error>> {
6158
}
6259

6360
pub fn is_sqlite_file(path: &str) -> Result<bool, Box<dyn Error>> {
64-
if get_path_type(&Path::new(path)) != PathType::File {
61+
if get_path_type(Path::new(path)) != PathType::File {
6562
return Ok(false);
6663
}
6764

@@ -90,9 +87,9 @@ pub fn fetch_rows<T>(
9087
where
9188
T: for<'r> serde::Deserialize<'r>,
9289
{
93-
let mut rows = stmt.query_and_then(params, |r| serde_rusqlite::from_row::<T>(r))?;
90+
let rows = stmt.query_and_then(params, |r| serde_rusqlite::from_row::<T>(r))?;
9491
let mut data = Vec::new();
95-
while let Some(row) = rows.next() {
92+
for row in rows {
9693
data.push(row.map_err(|e| e.to_string())?);
9794
}
9895
Ok(data)

src/wasm/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::process::Command;
22

33
fn main() {
44
let output = Command::new("git")
5-
.args(&["rev-parse", "HEAD"])
5+
.args(["rev-parse", "HEAD"])
66
.output()
77
.expect("Git is required to build");
88
let git_hash = String::from_utf8(output.stdout).unwrap();

src/wasm/src/dispatcher.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ impl<'a> Dispatcher<'a> {
141141
};
142142

143143
// Determine if we are bundled ONLY and the bundled cycle is newer than the installed (old bundled) cycle
144-
let bundled_updated = if is_bundled.is_some() && is_bundled.unwrap() {
144+
let bundled_updated = if is_bundled.is_some_and(|x| x) {
145+
// Clippy yells but this isn't good to switch until if-let chaining is implemented (Rust 2024)
145146
if installed_cycle.is_some() && bundled_cycle.is_some() {
146147
bundled_cycle.unwrap() > installed_cycle.unwrap()
147148
} else {
@@ -157,8 +158,8 @@ impl<'a> Dispatcher<'a> {
157158
// If we are bundled and the installed cycle is older than the bundled cycle, we need to copy the bundled database to the work location. Or if we haven't installed anything yet, we need to copy the bundled database to the work location
158159
if bundled_updated || need_to_copy {
159160
match util::copy_files_to_folder(
160-
&Path::new(consts::NAVIGATION_DATA_DEFAULT_LOCATION),
161-
&Path::new(consts::NAVIGATION_DATA_WORK_LOCATION),
161+
Path::new(consts::NAVIGATION_DATA_DEFAULT_LOCATION),
162+
Path::new(consts::NAVIGATION_DATA_WORK_LOCATION),
162163
) {
163164
Ok(_) => {
164165
// Set the internal state to bundled
@@ -178,7 +179,7 @@ impl<'a> Dispatcher<'a> {
178179
}
179180

180181
// Finally, set the active database
181-
if path_exists(&Path::new(consts::NAVIGATION_DATA_WORK_LOCATION)) {
182+
if path_exists(Path::new(consts::NAVIGATION_DATA_WORK_LOCATION)) {
182183
match self
183184
.database
184185
.set_active_database(consts::NAVIGATION_DATA_WORK_LOCATION.to_owned())
@@ -196,16 +197,13 @@ impl<'a> Dispatcher<'a> {
196197
}
197198

198199
fn on_download_finish(&mut self) {
199-
match navigation_database::util::find_sqlite_file(consts::NAVIGATION_DATA_WORK_LOCATION) {
200-
Ok(path) => {
201-
match self.database.set_active_database(path) {
202-
Ok(_) => {}
203-
Err(e) => {
204-
println!("[NAVIGRAPH] Failed to set active database: {}", e);
205-
}
206-
};
207-
}
208-
Err(_) => {}
200+
if let Ok(path) = navigation_database::util::find_sqlite_file(consts::NAVIGATION_DATA_WORK_LOCATION) {
201+
match self.database.set_active_database(path) {
202+
Ok(_) => {}
203+
Err(e) => {
204+
println!("[NAVIGRAPH] Failed to set active database: {}", e);
205+
}
206+
};
209207
}
210208
}
211209

src/wasm/src/download/zip_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<R: io::Read + io::Seek> ZipFileHandler<R> {
7373
if self.current_file_index >= self.zip_file_count {
7474
let fix_file = &self.path_buf.join("foo.txt");
7575

76-
if !util::path_exists(&fix_file) {
76+
if !util::path_exists(fix_file) {
7777
fs::File::create(fix_file)?;
7878
}
7979

src/wasm/src/meta.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@ use crate::{
1414
util::path_exists,
1515
};
1616

17-
#[derive(serde::Serialize, serde::Deserialize, Debug)]
17+
#[derive(serde::Serialize, serde::Deserialize, Debug, Default)]
1818
pub struct InternalState {
1919
pub is_bundled: bool,
2020
}
2121

22-
impl Default for InternalState {
23-
fn default() -> Self {
24-
Self { is_bundled: false }
25-
}
26-
}
27-
2822
#[derive(serde::Serialize, Clone, Copy, Debug, PartialEq, Eq)]
2923
pub enum InstallStatus {
3024
Bundled,
@@ -71,8 +65,8 @@ pub struct InstalledNavigationDataCycleInfo {
7165

7266
pub fn get_internal_state() -> Result<InternalState, Box<dyn Error>> {
7367
let config_path = Path::new(consts::NAVIGATION_DATA_INTERNAL_CONFIG_LOCATION);
74-
if !path_exists(&config_path) {
75-
return Err("Internal config file does not exist")?;
68+
if !path_exists(config_path) {
69+
Err("Internal config file does not exist")?;
7670
}
7771

7872
let config_file = std::fs::File::open(config_path)?;
@@ -196,31 +190,19 @@ pub fn get_navigation_data_install_status(task: Rc<RefCell<Task>>) {
196190

197191
let navigation_data_status = NavigationDataStatus {
198192
status,
199-
installed_format: match &installed_cycle_info {
200-
Some(installed_cycle_info) => Some(installed_cycle_info.format.clone()),
201-
None => None,
202-
},
203-
installed_revision: match &installed_cycle_info {
204-
Some(installed_cycle_info) => Some(installed_cycle_info.revision.clone()),
205-
None => None,
206-
},
207-
installed_cycle: match &installed_cycle_info {
208-
Some(installed_cycle_info) => Some(installed_cycle_info.cycle.clone()),
209-
None => None,
210-
},
193+
installed_format: installed_cycle_info.as_ref().map(|installed_cycle_info| installed_cycle_info.format.clone()),
194+
installed_revision: installed_cycle_info.as_ref().map(|installed_cycle_info| installed_cycle_info.revision.clone()),
195+
installed_cycle: installed_cycle_info.as_ref().map(|installed_cycle_info| installed_cycle_info.cycle.clone()),
211196
install_path: if status == InstallStatus::Manual {
212197
Some(consts::NAVIGATION_DATA_WORK_LOCATION.to_string())
213198
} else {
214199
None
215200
},
216-
validity_period: match &installed_cycle_info {
217-
Some(installed_cycle_info) => Some(installed_cycle_info.validity_period.clone()),
218-
None => None,
219-
},
201+
validity_period: installed_cycle_info.as_ref().map(|installed_cycle_info| installed_cycle_info.validity_period.clone()),
220202
latest_cycle: response_struct.cycle,
221203
};
222204

223-
let status_as_value = match serde_json::to_value(&navigation_data_status) {
205+
let status_as_value = match serde_json::to_value(navigation_data_status) {
224206
Ok(status_as_value) => status_as_value,
225207
Err(e) => {
226208
task.borrow_mut().status = TaskStatus::Failure(e.to_string());

0 commit comments

Comments
 (0)