Merge pull request #436 from Kijewski/pr-no-loop-first

`loop.first` is known by being at `index == 0`
This commit is contained in:
Guillaume Gomez 2025-05-17 11:49:05 +02:00 committed by GitHub
commit 428ff19932
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 3 deletions

View File

@ -48,7 +48,6 @@ where
item,
LoopItem {
index,
first: index == 0,
last: self.iter.peek().is_none(),
},
)
@ -59,7 +58,6 @@ where
#[derive(Copy, Clone)]
pub struct LoopItem {
pub index: usize,
pub first: bool,
pub last: bool,
}

View File

@ -369,7 +369,7 @@ impl<'a> Generator<'a, '_> {
buf.write("_loop_item.index");
return Ok(DisplayWrap::Unwrapped);
} else if attr.name == "first" {
buf.write("_loop_item.first");
buf.write("(_loop_item.index == 0)");
return Ok(DisplayWrap::Unwrapped);
} else if attr.name == "last" {
buf.write("_loop_item.last");