collections: Enable IndexMut for some collections
This commit enables implementations of IndexMut for a number of collections, including Vec, RingBuf, SmallIntMap, TrieMap, TreeMap, and HashMap. At the same time this deprecates the `get_mut` methods on vectors in favor of using the indexing notation. cc #18424
This commit is contained in:
parent
18a3db6aa1
commit
1d356624a1
46 changed files with 165 additions and 271 deletions
|
|
@ -426,7 +426,7 @@ impl<T> Buffer<T> {
|
|||
fn enqueue(&mut self, t: T) {
|
||||
let pos = (self.start + self.size) % self.buf.len();
|
||||
self.size += 1;
|
||||
let prev = mem::replace(self.buf.get_mut(pos), Some(t));
|
||||
let prev = mem::replace(&mut self.buf[pos], Some(t));
|
||||
assert!(prev.is_none());
|
||||
}
|
||||
|
||||
|
|
@ -434,7 +434,7 @@ impl<T> Buffer<T> {
|
|||
let start = self.start;
|
||||
self.size -= 1;
|
||||
self.start = (self.start + 1) % self.buf.len();
|
||||
self.buf.get_mut(start).take().unwrap()
|
||||
self.buf[start].take().unwrap()
|
||||
}
|
||||
|
||||
fn size(&self) -> uint { self.size }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue