Skip to content

Commit 0d3c415

Browse files
committed
Add capacity() to VecMap
Changed capacity() tag to unstable and fixed doc assert
1 parent 3a325c6 commit 0d3c415

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcollections/vec_map.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ impl<V> VecMap<V> {
115115
VecMap { v: Vec::with_capacity(capacity) }
116116
}
117117

118+
/// Returns the number of elements the `VecMap` can hold without
119+
/// reallocating.
120+
///
121+
/// # Example
122+
///
123+
/// ```
124+
/// use std::collections::VecMap;
125+
/// let map: VecMap<String> = VecMap::with_capacity(10);
126+
/// assert!(map.capacity() >= 10);
127+
/// ```
128+
#[inline]
129+
#[unstable = "matches collection reform specification, waiting for dust to settle"]
130+
pub fn capacity(&self) -> uint {
131+
self.v.capacity()
132+
}
133+
118134
/// Returns an iterator visiting all keys in ascending order by the keys.
119135
/// The iterator's element type is `uint`.
120136
#[unstable = "matches collection reform specification, waiting for dust to settle"]

0 commit comments

Comments
 (0)