Skip to content

Commit 9c5333b

Browse files
committed
Fix linting issues
1 parent 69cca36 commit 9c5333b

File tree

13 files changed

+147
-136
lines changed

13 files changed

+147
-136
lines changed

meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ project(
99
]
1010
)
1111

12+
env = environment()
13+
env.set('RUSTC', '')
14+
1215
fs = import('fs')
1316
rust = import('rust')
1417

src/bin/efivar.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use crate::efivar::print_mode::{Decimal, Verbose};
2-
use crate::efivar::types::PrintMode;
3-
use clap;
4-
use efivar;
1+
use efivar::{
2+
self,
3+
print_mode::{Decimal, Verbose},
4+
types::PrintMode,
5+
};
56
use ignore_result::Ignore;
67
use std::io;
78
use std::process::ExitCode;
89

910
fn create_parser() -> clap::Command {
10-
return clap::Command::new("efivar")
11+
clap::Command::new("efivar")
1112
.args_override_self(true)
1213
.disable_help_flag(true)
1314
.disable_version_flag(true)
@@ -82,7 +83,7 @@ fn create_parser() -> clap::Command {
8283
.long("guids-list-path")
8384
.value_name("guids-list-path")
8485
.default_value(efivar::efi_guids::DEFAULT_GUIDS_LIST_PATH)
85-
.help(format!("specify path to GUIDs list file."))
86+
.help("specify path to GUIDs list file.".to_string())
8687
.action(clap::ArgAction::Set)
8788
)
8889
.arg(clap::Arg::new("list-guids")
@@ -108,7 +109,7 @@ fn create_parser() -> clap::Command {
108109
.long("usage")
109110
.help("ignored for compatibility")
110111
.action(clap::ArgAction::Help)
111-
);
112+
)
112113
}
113114

114115
fn list_variables(_parser_args: clap::ArgMatches) -> ExitCode {
@@ -120,7 +121,7 @@ fn list_variables(_parser_args: clap::ArgMatches) -> ExitCode {
120121
for v in variables {
121122
println!("{}", v);
122123
}
123-
return std::process::ExitCode::from(0);
124+
std::process::ExitCode::from(0)
124125
}
125126
Err(_) => {
126127
let efivar_variables: efivar::efivar::EfiVariables =
@@ -130,11 +131,11 @@ fn list_variables(_parser_args: clap::ArgMatches) -> ExitCode {
130131
for v in variables {
131132
println!("{}", v);
132133
}
133-
return std::process::ExitCode::from(0);
134+
std::process::ExitCode::from(0)
134135
}
135136
Err(e) => {
136137
eprintln!("Failed to access EFI variables: {}", e);
137-
return std::process::ExitCode::from(1);
138+
std::process::ExitCode::from(1)
138139
}
139140
}
140141
}
@@ -152,7 +153,7 @@ fn print_variable(parser_args: clap::ArgMatches, print_mode: efivar::types::Prin
152153
PrintMode::VERBOSE => println!("{}", Verbose(&var)),
153154
PrintMode::DECIMAL => println!("{}", Decimal(&var)),
154155
}
155-
return std::process::ExitCode::from(0);
156+
std::process::ExitCode::from(0)
156157
}
157158
Err(_) => {
158159
let efivar_variables: efivar::efivar::EfiVariables =
@@ -163,25 +164,25 @@ fn print_variable(parser_args: clap::ArgMatches, print_mode: efivar::types::Prin
163164
PrintMode::VERBOSE => println!("{}", Verbose(&var)),
164165
PrintMode::DECIMAL => println!("{}", Decimal(&var)),
165166
}
166-
return std::process::ExitCode::from(0);
167+
std::process::ExitCode::from(0)
167168
}
168169
Err(e) => {
169170
eprintln!("Failed to read variable: {}", e);
170-
return std::process::ExitCode::from(1);
171+
std::process::ExitCode::from(1)
171172
}
172173
}
173174
}
174-
};
175+
}
175176
}
176177
None => {
177178
eprintln!("No variable name given");
178-
return std::process::ExitCode::from(1);
179+
std::process::ExitCode::from(1)
179180
}
180-
};
181+
}
181182
}
182183

183184
fn append_attributes(parser_args: clap::ArgMatches) -> ExitCode {
184-
return std::process::ExitCode::from(0);
185+
std::process::ExitCode::from(0)
185186
}
186187

187188
fn list_guids(parser_args: clap::ArgMatches) -> ExitCode {
@@ -197,46 +198,44 @@ fn list_guids(parser_args: clap::ArgMatches) -> ExitCode {
197198
return std::process::ExitCode::from(e.raw_os_error().unwrap_or(1) as u8);
198199
}
199200
}
200-
return std::process::ExitCode::from(0);
201+
std::process::ExitCode::from(0)
201202
}
202203

203204
fn write_variable(parser_args: clap::ArgMatches) -> ExitCode {
204-
return std::process::ExitCode::from(0);
205+
std::process::ExitCode::from(0)
205206
}
206207

207208
fn import_variable(parser_args: clap::ArgMatches) -> ExitCode {
208-
return std::process::ExitCode::from(0);
209+
std::process::ExitCode::from(0)
209210
}
210211

211212
fn export_variable(parser_args: clap::ArgMatches) -> ExitCode {
212-
return std::process::ExitCode::from(0);
213+
std::process::ExitCode::from(0)
213214
}
214215

215216
fn main() -> ExitCode {
216217
let mut parser = create_parser();
217218
let matches = parser.get_matches_mut();
218219
if matches.get_flag("list") {
219-
return list_variables(matches);
220+
list_variables(matches)
220221
} else if matches.get_flag("print") {
221-
return print_variable(matches, efivar::types::PrintMode::VERBOSE);
222+
print_variable(matches, efivar::types::PrintMode::VERBOSE)
222223
} else if matches.get_flag("append") {
223-
return append_attributes(matches);
224+
append_attributes(matches)
224225
} else if matches.get_flag("list-guids") {
225-
return list_guids(matches);
226+
list_guids(matches)
226227
} else if matches.get_flag("write") {
227-
return write_variable(matches);
228+
write_variable(matches)
228229
} else if matches.get_flag("print-decimal") {
229-
return print_variable(matches, efivar::types::PrintMode::DECIMAL);
230+
print_variable(matches, efivar::types::PrintMode::DECIMAL)
230231
} else if matches.get_one::<&str>("import").is_some() {
231-
return import_variable(matches);
232+
import_variable(matches)
232233
} else if matches.get_one::<&str>("export").is_some() {
233-
return export_variable(matches);
234+
export_variable(matches)
235+
} else if matches.get_one::<String>("name").is_some() {
236+
return print_variable(matches, efivar::types::PrintMode::VERBOSE);
234237
} else {
235-
if matches.get_one::<String>("name").is_some() {
236-
return print_variable(matches, efivar::types::PrintMode::VERBOSE);
237-
} else {
238-
parser.write_help(&mut io::stderr()).ignore();
239-
return std::process::ExitCode::from(1);
240-
}
238+
parser.write_help(&mut io::stderr()).ignore();
239+
return std::process::ExitCode::from(1);
241240
}
242241
}

src/lib/efivar/efi_guids.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::HashMap;
66
use std::fs::File;
77
use std::io::{BufReader, Error};
88

9-
pub const DEFAULT_GUIDS_LIST_PATH: &'static str = efi_guids_list_path::VALUE;
9+
pub const DEFAULT_GUIDS_LIST_PATH: &str = efi_guids_list_path::VALUE;
1010

1111
pub enum GuidListSortField {
1212
Guid,
@@ -27,11 +27,15 @@ struct JsonEfiGuidListEntry {
2727

2828
impl Default for EfiGuidList {
2929
fn default() -> Self {
30-
return EfiGuidList { guids_map: None };
30+
Self::new()
3131
}
3232
}
3333

3434
impl EfiGuidList {
35+
pub fn new() -> Self {
36+
Self { guids_map: None }
37+
}
38+
3539
pub fn load(&mut self, path: &String) -> Result<(), Error> {
3640
let mut map: HashMap<String, EfiGuidListEntry> = HashMap::new();
3741
let reader = BufReader::new(File::open(path)?);
@@ -73,15 +77,12 @@ impl EfiGuidList {
7377

7478
pub fn guids(&self, sorted_by: GuidListSortField) -> Vec<&EfiGuidListEntry> {
7579
match sorted_by {
76-
GuidListSortField::None => {
77-
let guids = self
78-
.guids_map
79-
.as_ref()
80-
.unwrap()
81-
.values()
82-
.collect::<Vec<_>>();
83-
return guids;
84-
}
80+
GuidListSortField::None => self
81+
.guids_map
82+
.as_ref()
83+
.unwrap()
84+
.values()
85+
.collect::<Vec<_>>(),
8586
GuidListSortField::Guid => {
8687
let mut sorted_guids = self
8788
.guids_map
@@ -90,7 +91,7 @@ impl EfiGuidList {
9091
.values()
9192
.collect::<Vec<_>>();
9293
sorted_guids.sort_unstable_by(|e1, e2| e1.guid.cmp(&e2.guid));
93-
return sorted_guids;
94+
sorted_guids
9495
}
9596
GuidListSortField::Id => {
9697
let mut sorted_guids = self
@@ -100,7 +101,7 @@ impl EfiGuidList {
100101
.values()
101102
.collect::<Vec<_>>();
102103
sorted_guids.sort_unstable_by(|e1, e2| e1.name.cmp(&e2.name));
103-
return sorted_guids;
104+
sorted_guids
104105
}
105106
}
106107
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub const VALUE: &'static str = "@GUIDS_LIST_PATH@";
1+
pub const VALUE: &str = "@GUIDS_LIST_PATH@";

src/lib/efivar/efi_variable_attributes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub static APPEND_WRITE: EfiVariableAttribute = EfiVariableAttribute::new("Appen
1616
pub static ENHANCED_AUTHENTICATED_ACCESS: EfiVariableAttribute =
1717
EfiVariableAttribute::new("Enhanced Authenticated Access", 0x80);
1818

19-
pub static EFI_VARIABLE_ATTRIBUTES: &'static [&EfiVariableAttribute] = &[
19+
pub static EFI_VARIABLE_ATTRIBUTES: &[&EfiVariableAttribute] = &[
2020
&NON_VOLATILE,
2121
&BOOTSERVICE_ACCESS,
2222
&RUNTIME_ACCESS,
@@ -34,5 +34,5 @@ pub fn parse_attributes<'a>(value: u32) -> HashSet<&'a EfiVariableAttribute> {
3434
set.insert(*attr);
3535
}
3636
}
37-
return set;
37+
set
3838
}

0 commit comments

Comments
 (0)