Is it possible to simplify this check?
path.extension().and_then(|it| it.to_str()) = Some("rs")
Is it possible to simplify this check?
path.extension().and_then(|it| it.to_str()) = Some("rs")
You can just compare to an OsStr
:
path.extension() == Some(OsStr::new("rs"))
Nightly would let you do
path.extension().contains(&"rs")
Two more options:
path.extension().map(|it| it == "rs").unwrap_or(false)
(I think that one is the most clear on intent)
path.extension().unwrap_or(OsStr::new("")) == "rs"
.extension().contains()
is correct but reads wrong.
Perfect!
path.extension().unwrap_or_default() == "rs"
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.