We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Path.ends_with
str.ends_with
It catches a potential gotcha.
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").
path.ends_with(".ext")
path.ends_with(".rustup")
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 ;) }
The text was updated successfully, but these errors were encountered:
path_ends_with_ext
daadab5
Successfully merging a pull request may close this issue.
What it does
Path.ends_with
works differently thanstr.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, likepath.ends_with(".rustup")
.Example
Could be written as:
The text was updated successfully, but these errors were encountered: