Skip to content

Commit

Permalink
Merge pull request #1442 from programmerjake/add-pop-punct
Browse files Browse the repository at this point in the history
add Punctuated::pop_punct()
  • Loading branch information
dtolnay committed Apr 11, 2023
2 parents 2dc7988 + 81c5035 commit ed15fda
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/punctuated.rs
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 ed15fda

Please sign in to comment.