From 81c503550e4080f86eb377a214c31245e4a64eeb Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 10 Apr 2023 23:47:15 -0700 Subject: [PATCH] add Punctuated::pop_punct() Fixes: #1043 --- src/punctuated.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/punctuated.rs b/src/punctuated.rs index 7880eb29ca..a4278081c4 100644 --- a/src/punctuated.rs +++ b/src/punctuated.rs @@ -187,6 +187,18 @@ impl Punctuated { } } + /// Removes the trailing punctuation from this punctuated sequence, or + /// `None` if there isn't any. + pub fn pop_punct(&mut self) -> Option

{ + 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 {