Skip to content

Commit

Permalink
refactor(toml): Simplify file/dir target inference
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 5, 2024
1 parent bc3ebc6 commit 143ccd8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,18 +686,18 @@ fn infer_any(entry: &DirEntry) -> Option<(String, PathBuf)> {

fn infer_file(entry: &DirEntry) -> Option<(String, PathBuf)> {
let path = entry.path();
path.file_stem()
.and_then(|p| p.to_str())
.map(|p| (p.to_owned(), path.clone()))
let stem = path.file_stem()?.to_str()?.to_owned();
Some((stem, path))
}

fn infer_subdirectory(entry: &DirEntry) -> Option<(String, PathBuf)> {
let path = entry.path();
let main = path.join("main.rs");
let name = path.file_name().and_then(|n| n.to_str());
match (name, main.exists()) {
(Some(name), true) => Some((name.to_owned(), main)),
_ => None,
let name = path.file_name()?.to_str()?.to_owned();
if main.exists() {
Some((name, main))
} else {
None
}
}

Expand Down

0 comments on commit 143ccd8

Please sign in to comment.