Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8d4cb6e

Browse files
author
Ruben Schmidmeister
committed
Use peek() instead of checking indexes
1 parent 9b98dd7 commit 8d4cb6e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/attr/doc_comment.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ impl<'a> DocCommentFormatter<'a> {
1616
impl Display for DocCommentFormatter<'_> {
1717
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1818
let opener = self.style.opener().trim_end();
19-
2019
let literal_as_str = self.literal.as_str().get();
21-
let line_count = literal_as_str.lines().count();
22-
let last_line_index = line_count - 1;
23-
let lines = literal_as_str.lines().enumerate();
2420

25-
for (index, line) in lines {
26-
if index == last_line_index {
21+
let mut lines = literal_as_str.lines().peekable();
22+
while let Some(line) = lines.next() {
23+
let is_last_line = lines.peek().is_none();
24+
if is_last_line {
2725
write!(formatter, "{}{}", opener, line)?;
2826
} else {
2927
writeln!(formatter, "{}{}", opener, line)?;

0 commit comments

Comments
 (0)