diff --git a/src/lib.rs b/src/lib.rs index 7fc6f1a..92da94e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -969,6 +969,21 @@ impl Slab { key } + /// Insert values in the slab from an iterator. + /// + /// # Examples + /// + /// ``` + /// # use slab::*; + /// let mut slab = Slab::with_capacity(5); + /// slab.extend(1..9); + /// assert_eq!(slab[5], 6); + /// assert_eq!(slab.len(), 8); + /// ``` + pub fn extend>(&mut self, iter: I) -> Vec { + iter.into_iter().map(|x| self.insert(x)).collect() + } + /// Returns the key of the next vacant entry. /// /// This function returns the key of the vacant entry which will be used