Skip to content

Commit 6c2a038

Browse files
committed
loader: Use strip_prefix
Clippy suggests that using strip_prefix over str::starts_with and slicing[1]. [1] https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip Signed-off-by: Akira Moroo <[email protected]>
1 parent 4abdf68 commit 6c2a038

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/loader.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ fn default_entry_file(f: &mut fat::File) -> Result<[u8; 260], fat::Error> {
6161

6262
let conf = unsafe { core::str::from_utf8_unchecked(&data) };
6363
for line in conf.lines() {
64-
if line.starts_with("default") {
65-
let entry = line["default".len()..].trim();
64+
if let Some(entry) = line.strip_prefix("default") {
6665
entry_file_name[0..entry.len()].copy_from_slice(entry.as_bytes());
6766
}
6867
}
@@ -89,16 +88,13 @@ fn parse_entry(f: &mut fat::File) -> Result<LoaderConfig, fat::Error> {
8988

9089
let conf = unsafe { core::str::from_utf8_unchecked(&data) };
9190
for line in conf.lines() {
92-
if line.starts_with("linux") {
93-
let entry = line["linux".len()..].trim();
91+
if let Some(entry) = line.strip_prefix("linux") {
9492
loader_config.bzimage_path[0..entry.len()].copy_from_slice(entry.as_bytes());
9593
}
96-
if line.starts_with("options") {
97-
let entry = line["options".len()..].trim();
94+
if let Some(entry) = line.strip_prefix("options") {
9895
loader_config.cmdline[0..entry.len()].copy_from_slice(entry.as_bytes());
9996
}
100-
if line.starts_with("initrd") {
101-
let entry = line["initrd".len()..].trim();
97+
if let Some(entry) = line.strip_prefix("initrd") {
10298
loader_config.initrd_path[0..entry.len()].copy_from_slice(entry.as_bytes());
10399
}
104100
}

0 commit comments

Comments
 (0)