Skip to content

Commit

Permalink
add Punctuated::pop_punct()
Browse files Browse the repository at this point in the history
  • Loading branch information
programmerjake committed Apr 11, 2023
1 parent 2dc7988 commit 81c5035
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/punctuated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ impl<T, P> Punctuated<T, P> {
}
}

/// Removes the trailing punctuation from this punctuated sequence, or
/// `None` if there isn't any.
pub fn pop_punct(&mut self) -> Option<P> {
if self.last.is_some() {
None
} else {
let (t, p) = self.inner.pop()?;
self.last = Some(Box::new(t));
Some(p)
}
}

/// Determines whether this punctuated sequence ends with a trailing
/// punctuation.
pub fn trailing_punct(&self) -> bool {
Expand Down

0 comments on commit 81c5035

Please sign in to comment.