Closed
Description
What it does
Path.ends_with
works differently than str.ends_with
, and an attempt to match a file extension can unexpectedly only compare to the whole file name.
Advantage
It catches a potential gotcha.
Drawbacks
path.ends_with(".ext")
is a mistake when used with file name extensions, but could be valid for a dot-file, like path.ends_with(".rustup")
.
Example
fn is_markdown(path: &Path) -> bool {
path.ends_with(".md")
}
Could be written as:
fn is_markdown(path: &Path) -> bool {
path.extension().map_or(false, |ext| ext == "md") // then run clippy --fix to make it case-insensitive ;)
}