Skip to content

Commit

Permalink
fix ref:#88 cargo-clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed Jun 20, 2022
1 parent ec079d4 commit e89deae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl SystemEnv {
if let Ok(out) = Command::new("cargo").arg("tree").output() {
let input = String::from_utf8(out.stdout)?;
if let Some(index) = input.find('\n') {
let lines = filter_cargo_tree(input[index..].split('\n').collect());
let lines =
filter_cargo_tree(input.get(index..).unwrap_or_default().split('\n').collect());
update_val(CARGO_TREE, lines);
}
}
Expand Down Expand Up @@ -168,7 +169,7 @@ mod dep_source_replace {
} else if let Some(index) = input.find(" (ssh") {
(DEP_REPLACE_GIT, index)
} else if let (Some(start), Some(end)) = (input.find(" ("), input.find(')')) {
let path = input[start + 2..end].trim();
let path = input.get(start + 2..end).unwrap_or_default().trim();
if path_exists(path) {
(DEP_REPLACE_PATH, start)
} else {
Expand All @@ -177,7 +178,7 @@ mod dep_source_replace {
} else {
(DEP_REPLACE_NONE, input.len())
};
format!("{}{}", &input[..index], val)
format!("{}{}", &input.get(..index).unwrap_or_default(), val)
}

pub fn filter_cargo_tree(lines: Vec<&str>) -> String {
Expand Down
14 changes: 11 additions & 3 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Git {
let mut short_commit = commit.as_str();

if commit.len() > 8 {
short_commit = &short_commit[0..8];
short_commit = short_commit.get(0..8).unwrap();
}
self.update_str(SHORT_COMMIT, short_commit.to_string());
}
Expand Down Expand Up @@ -184,9 +184,17 @@ impl Git {
let ref_tag_prefix: &str = "refs/tags/";

if v.starts_with(ref_branch_prefix) {
branch = Some(v[ref_branch_prefix.len()..].to_string())
branch = Some(
v.get(ref_branch_prefix.len()..)
.unwrap_or_default()
.to_string(),
)
} else if v.starts_with(ref_tag_prefix) {
tag = Some(v[ref_tag_prefix.len()..].to_string())
tag = Some(
v.get(ref_tag_prefix.len()..)
.unwrap_or_default()
.to_string(),
)
}
}
}
Expand Down

0 comments on commit e89deae

Please sign in to comment.