Skip to content
Closed
Changes from all commits
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
15 changes: 15 additions & 0 deletions src/with_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ pub enum Position {
Only,
}

impl Position {
/// Whether the current element is the first of the iterator,
/// regardless of length (includes both [`Position::First`]
/// and [`Position::Only`]).
pub fn is_first(&self) -> bool {
matches!(self, Self::First | Self::Only)
}
/// Whether the current element is the last of the iterator,
/// regardless of length (includes both [`Position::Last`]
/// and [`Position::Only`]).
pub fn is_last(&self) -> bool {
matches!(self, Self::Only | Self::Last)
}
}

impl<I: Iterator> Iterator for WithPosition<I> {
type Item = (Position, I::Item);

Expand Down