8000 Prefer `Option::map`/etc over `match` wherever it improves clarity by Wallacoloo · Pull Request #52658 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Prefer Option::map/etc over match wherever it improves clarity #52658

New issue

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

Merged
merged 4 commits into from
Jul 25, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
libcore: Prefer Option::map over match where applicable
  • Loading branch information
Wallacoloo committed Jul 24, 2018
commit 727bd7de7e6332482ee2765d46bfd00d89386d4b
11 changes: 4 additions & 7 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,10 @@ impl<'a> Iterator for CharIndices<'a> {
impl<'a> DoubleEndedIterator for CharIndices<'a> {
#[inline]
fn next_back(&mut self) -> Option<(usize, char)> {
match self.iter.next_back() {
None => None,
Some(ch) => {
let index = self.front_offset + self.iter.iter.len();
Some((index, ch))
}
}
self.iter.next_back().map(|ch| {
let index = self.front_offset + self.iter.iter.len();
(index, ch)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other possibility for code like this is to let ch = self.iter.next_back()?;, though I don't know if that's better, nor if it's canonical style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, I forgot ? had been extended to support more than just Result types. If you want, I can spin up another PR for that - as it looks like these commits were just merged - but otherwise I suppose I'll just leave this be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not confident that it's better, so it's probably not worth bothering with changing -- going to something other than the manual match, as you did, is the important part here.

}
}

Expand Down
0