]> git.proxmox.com Git - rustc.git/blobdiff - src/librustc_data_structures/indexed_vec.rs
New upstream version 1.17.0+dfsg1
[rustc.git] / src / librustc_data_structures / indexed_vec.rs
index 00cea9cbdf6b7100aac27aa01164f32810c28afe..3f478d7c165d13b1b903e35e0f72f2b53678d5d6 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std::collections::range::RangeArgument;
 use std::fmt::Debug;
 use std::iter::{self, FromIterator};
 use std::slice;
@@ -145,6 +146,18 @@ impl<I: Idx, T> IndexVec<I, T> {
         self.raw.iter_mut().enumerate().map(IntoIdx { _marker: PhantomData })
     }
 
+    #[inline]
+    pub fn drain<'a, R: RangeArgument<usize>>(
+        &'a mut self, range: R) -> impl Iterator<Item=T> + 'a {
+        self.raw.drain(range)
+    }
+
+    #[inline]
+    pub fn drain_enumerated<'a, R: RangeArgument<usize>>(
+        &'a mut self, range: R) -> impl Iterator<Item=(I, T)> + 'a {
+        self.raw.drain(range).enumerate().map(IntoIdx { _marker: PhantomData })
+    }
+
     #[inline]
     pub fn last(&self) -> Option<I> {
         self.len().checked_sub(1).map(I::new)
@@ -164,6 +177,16 @@ impl<I: Idx, T> IndexVec<I, T> {
     pub fn truncate(&mut self, a: usize) {
         self.raw.truncate(a)
     }
+
+    #[inline]
+    pub fn get(&self, index: I) -> Option<&T> {
+        self.raw.get(index.index())
+    }
+
+    #[inline]
+    pub fn get_mut(&mut self, index: I) -> Option<&mut T> {
+        self.raw.get_mut(index.index())
+    }
 }
 
 impl<I: Idx, T> Index<I> for IndexVec<I, T> {