about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAaron Liblong <liblonga@physics.utoronto.ca>2014-12-04 12:14:06 -0500
committerAaron Liblong <liblonga@physics.utoronto.ca>2014-12-04 13:21:43 -0500
commit0d3c41561751bbcbc8f2fccf7369280e35dbb68f (patch)
tree477defaf7c572cfdb2720fdc97afc4e19960c38f /src
parent3a325c666d2cb7e297bf3057ff2442f96a79428b (diff)
downloadrust-0d3c41561751bbcbc8f2fccf7369280e35dbb68f.tar.gz
rust-0d3c41561751bbcbc8f2fccf7369280e35dbb68f.zip
Add capacity() to VecMap
Changed capacity() tag to unstable and fixed doc assert
Diffstat (limited to 'src')
-rw-r--r--src/libcollections/vec_map.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs
index 36e66ed27f3..986e7ef5bc2 100644
--- a/src/libcollections/vec_map.rs
+++ b/src/libcollections/vec_map.rs
@@ -115,6 +115,22 @@ impl<V> VecMap<V> {
         VecMap { v: Vec::with_capacity(capacity) }
     }
 
+    /// Returns the number of elements the `VecMap` can hold without
+    /// reallocating.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// use std::collections::VecMap;
+    /// let map: VecMap<String> = VecMap::with_capacity(10);
+    /// assert!(map.capacity() >= 10);
+    /// ```
+    #[inline]
+    #[unstable = "matches collection reform specification, waiting for dust to settle"]
+    pub fn capacity(&self) -> uint {
+        self.v.capacity()
+    }
+
     /// Returns an iterator visiting all keys in ascending order by the keys.
     /// The iterator's element type is `uint`.
     #[unstable = "matches collection reform specification, waiting for dust to settle"]