Skip to content

Commit

Permalink
chore: format and clear up monadic chains in util.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
reo101 committed Mar 6, 2024
1 parent 279223c commit 7dce0b4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ pub fn command_exists<S: AsRef<OsStr>>(program: S) -> bool {

/// Climb each parent directory from a given starting directory until we find Cargo.toml
pub fn discover_project_root_from_path(start_from: impl AsRef<Path>) -> Result<Option<PathBuf>> {
discover_file_up_from_path(start_from, |path| {
if path
.file_name().and_then(std::ffi::OsStr::to_str)
discover_file_up_from_path(start_from, |path| -> Option<PathBuf> {
path.file_name()
.and_then(std::ffi::OsStr::to_str)
.is_some_and(|name| name == "Cargo.toml")
{
path.parent().map(PathBuf::from)
} else {
None
}
.then(|| {
path.parent()
.expect("Cargo.toml is sure to have a parent directory")
.into()
})
})
}

Expand Down

0 comments on commit 7dce0b4

Please sign in to comment.