Square bracket indexing for Punctuated
diff --git a/src/punctuated.rs b/src/punctuated.rs
index ca34d22..38363b6 100644
--- a/src/punctuated.rs
+++ b/src/punctuated.rs
@@ -28,6 +28,7 @@
//! ```
use std::iter::FromIterator;
+use std::ops::{Index, IndexMut};
use std::slice;
use std::vec;
#[cfg(feature = "extra-traits")]
@@ -446,6 +447,20 @@
}
}
+impl<T, P> Index<usize> for Punctuated<T, P> {
+ type Output = T;
+
+ fn index(&self, index: usize) -> &Self::Output {
+ &self.inner[index].0
+ }
+}
+
+impl<T, P> IndexMut<usize> for Punctuated<T, P> {
+ fn index_mut(&mut self, index: usize) -> &mut Self::Output {
+ &mut self.inner[index].0
+ }
+}
+
#[cfg(feature = "parsing")]
impl<T, P> Punctuated<T, P>
where