From ef0f04c215d0be4f5937b2804a5e1ae2ff12e906 Mon Sep 17 00:00:00 2001 From: Tristan Guichaoua Date: Mon, 13 Mar 2023 15:18:55 +0100 Subject: [PATCH] Punctuated::remove(index) --- src/punctuated.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/punctuated.rs b/src/punctuated.rs index 007d157c59..dba53116c0 100644 --- a/src/punctuated.rs +++ b/src/punctuated.rs @@ -238,6 +238,23 @@ impl Punctuated { } } + /// Removes and returns the punctuated pair at position `index`. + /// + /// # Panics + /// + /// Panics if `index` is out of bounds. + pub fn remove(&mut self, index: usize) -> Pair { + assert!(index < self.len(), "Punctuated::remove: index out of range"); + + if index == self.inner.len() { + let t = self.last.take().unwrap(); + Pair::End(*t) + } else { + let (t, p) = self.inner.remove(index); + Pair::Punctuated(t, p) + } + } + /// Clears the sequence of all values and punctuation, making it empty. pub fn clear(&mut self) { self.inner.clear();