Skip to content

Commit e03e4c2

Browse files
committed
Align with _mut conventions
As per [RFC 52](https://github.com/rust-lang/rfcs/blob/master/active/0052-ownership-variants.md), use `_mut` suffixes to mark mutable variants, and `into_iter` for moving iterators. [breaking-change]
1 parent 946654a commit e03e4c2

File tree

15 files changed

+293
-68
lines changed

15 files changed

+293
-68
lines changed

src/libcollections/dlist.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,15 @@ impl<T> DList<T> {
475475
Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
476476
}
477477

478+
/// Deprecated: use `iter_mut`.
479+
#[deprecated = "use iter_mut"]
480+
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
481+
self.iter_mut()
482+
}
483+
478484
/// Provides a forward iterator with mutable references.
479485
#[inline]
480-
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
486+
pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
481487
let head_raw = match self.list_head {
482488
Some(ref mut h) => Rawlink::some(&mut **h),
483489
None => Rawlink::none(),
@@ -490,10 +496,15 @@ impl<T> DList<T> {
490496
}
491497
}
492498

499+
/// Deprecated: use `into_iter`.
500+
#[deprecated = "use into_iter"]
501+
pub fn move_iter(self) -> MoveItems<T> {
502+
self.into_iter()
503+
}
493504

494505
/// Consumes the list into an iterator yielding elements by value.
495506
#[inline]
496-
pub fn move_iter(self) -> MoveItems<T> {
507+
pub fn into_iter(self) -> MoveItems<T> {
497508
MoveItems{list: self}
498509
}
499510
}

src/libcollections/ringbuf.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ impl<T> RingBuf<T> {
250250
Items{index: 0, rindex: self.nelts, lo: self.lo, elts: self.elts.as_slice()}
251251
}
252252

253+
/// Deprecated: use `iter_mut`
254+
#[deprecated = "use iter_mut"]
255+
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
256+
self.iter_mut()
257+
}
258+
253259
/// Returns a front-to-back iterator which returns mutable references.
254260
///
255261
/// # Example
@@ -267,7 +273,7 @@ impl<T> RingBuf<T> {
267273
/// let b: &[_] = &[&mut 3, &mut 1, &mut 2];
268274
/// assert_eq!(buf.mut_iter().collect::<Vec<&mut int>>().as_slice(), b);
269275
/// ```
270-
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
276+
pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
271277
let start_index = raw_index(self.lo, self.elts.len(), 0);
272278
let end_index = raw_index(self.lo, self.elts.len(), self.nelts);
273279

src/libcollections/smallintmap.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ impl<V> SmallIntMap<V> {
260260
}
261261
}
262262

263+
/// Deprecated: use `iter_mut`
264+
#[deprecated = "use iter_mut"]
265+
pub fn mut_iter<'r>(&'r mut self) -> MutEntries<'r, V> {
266+
self.iter_mut()
267+
}
268+
263269
/// Returns an iterator visiting all key-value pairs in ascending order by the keys,
264270
/// with mutable references to the values.
265271
/// The iterator's element type is `(uint, &'r mut V)`.
@@ -282,14 +288,22 @@ impl<V> SmallIntMap<V> {
282288
/// assert_eq!(value, &"x");
283289
/// }
284290
/// ```
285-
pub fn mut_iter<'r>(&'r mut self) -> MutEntries<'r, V> {
291+
pub fn iter_mut<'r>(&'r mut self) -> MutEntries<'r, V> {
286292
MutEntries {
287293
front: 0,
288294
back: self.v.len(),
289295
iter: self.v.mut_iter()
290296
}
291297
}
292298

299+
/// Deprecated: use `into_iter` instead.
300+
#[deprecated = "use into_iter"]
301+
pub fn move_iter(&mut self)
302+
-> FilterMap<(uint, Option<V>), (uint, V),
303+
Enumerate<vec::MoveItems<Option<V>>>> {
304+
self.into_iter()
305+
}
306+
293307
/// Returns an iterator visiting all key-value pairs in ascending order by
294308
/// the keys, emptying (but not consuming) the original `SmallIntMap`.
295309
/// The iterator's element type is `(uint, &'r V)`.
@@ -309,7 +323,7 @@ impl<V> SmallIntMap<V> {
309323
///
310324
/// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
311325
/// ```
312-
pub fn move_iter(&mut self)
326+
pub fn into_iter(&mut self)
313327
-> FilterMap<(uint, Option<V>), (uint, V),
314328
Enumerate<vec::MoveItems<Option<V>>>>
315329
{

src/libcollections/treemap.rs

+60-19
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ impl<K: Ord, V> Map<K, V> for TreeMap<K, V> {
226226
}
227227

228228
impl<K: Ord, V> MutableMap<K, V> for TreeMap<K, V> {
229-
// See comments on def_tree_find_mut_with
229+
// See comments on tree_find_with_mut
230230
#[inline]
231231
fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V> {
232-
tree_find_mut_with(&mut self.root, |x| key.cmp(x))
232+
tree_find_with_mut(&mut self.root, |x| key.cmp(x))
233233
}
234234

235235
fn swap(&mut self, key: K, value: V) -> Option<V> {
@@ -361,6 +361,12 @@ impl<K: Ord, V> TreeMap<K, V> {
361361
RevEntries{iter: self.iter()}
362362
}
363363

364+
/// Deprecated: use `iter_mut`.
365+
#[deprecated = "use iter_mut"]
366+
pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, K, V> {
367+
self.iter_mut()
368+
}
369+
364370
/// Gets a lazy forward iterator over the key-value pairs in the
365371
/// map, with the values being mutable.
366372
///
@@ -383,15 +389,21 @@ impl<K: Ord, V> TreeMap<K, V> {
383389
/// assert_eq!(map.find(&"b"), Some(&12));
384390
/// assert_eq!(map.find(&"c"), Some(&3));
385391
/// ```
386-
pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, K, V> {
392+
pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> {
387393
MutEntries {
388394
stack: vec!(),
389-
node: mut_deref(&mut self.root),
395+
node: deref_mut(&mut self.root),
390396
remaining_min: self.length,
391397
remaining_max: self.length
392398
}
393399
}
394400

401+
/// Deprecated: use `rev_iter_mut`.
402+
#[deprecated = "use rev_iter_mut"]
403+
pub fn mut_rev_iter<'a>(&'a mut self) -> RevMutEntries<'a, K, V> {
404+
self.rev_iter_mut()
405+
}
406+
395407
/// Gets a lazy reverse iterator over the key-value pairs in the
396408
/// map, with the values being mutable.
397409
///
@@ -414,10 +426,15 @@ impl<K: Ord, V> TreeMap<K, V> {
414426
/// assert_eq!(map.find(&"b"), Some(&12));
415427
/// assert_eq!(map.find(&"c"), Some(&13));
416428
/// ```
417-
pub fn mut_rev_iter<'a>(&'a mut self) -> RevMutEntries<'a, K, V> {
429+
pub fn rev_iter_mut<'a>(&'a mut self) -> RevMutEntries<'a, K, V> {
418430
RevMutEntries{iter: self.mut_iter()}
419431
}
420432

433+
/// Deprecated: use `into_iter`.
434+
#[depreated = "use into_iter"]
435+
pub fn move_iter(self) -> MoveEntries<K, V> {
436+
self.into_iter()
437+
}
421438

422439
/// Gets a lazy iterator that consumes the treemap.
423440
///
@@ -434,7 +451,7 @@ impl<K: Ord, V> TreeMap<K, V> {
434451
/// let vec: Vec<(&str, int)> = map.move_iter().collect();
435452
/// assert_eq!(vec, vec![("a", 1), ("b", 2), ("c", 3)]);
436453
/// ```
437-
pub fn move_iter(self) -> MoveEntries<K, V> {
454+
pub fn into_iter(self) -> MoveEntries<K, V> {
438455
let TreeMap { root: root, length: length } = self;
439456
let stk = match root {
440457
None => vec!(),
@@ -477,6 +494,12 @@ impl<K, V> TreeMap<K, V> {
477494
tree_find_with(&self.root, f)
478495
}
479496

497+
/// Deprecated: use `find_with_mut`.
498+
#[deprecated = "use find_with_mut"]
499+
pub fn find_mut_with<'a>(&'a mut self, f:|&K| -> Ordering) -> Option<&'a mut V> {
500+
self.find_with_mut(f)
501+
}
502+
480503
/// Returns the value for which `f(key)` returns `Equal`. `f` is invoked
481504
/// with current key and guides tree navigation. That means `f` should
482505
/// be aware of natural ordering of the tree.
@@ -497,8 +520,8 @@ impl<K, V> TreeMap<K, V> {
497520
/// assert_eq!(t.find(&"User-Agent"), Some(&new_ua));
498521
/// ```
499522
#[inline]
500-
pub fn find_mut_with<'a>(&'a mut self, f:|&K| -> Ordering) -> Option<&'a mut V> {
501-
tree_find_mut_with(&mut self.root, f)
523+
pub fn find_with_mut<'a>(&'a mut self, f:|&K| -> Ordering) -> Option<&'a mut V> {
524+
tree_find_with_mut(&mut self.root, f)
502525
}
503526
}
504527

@@ -594,15 +617,21 @@ impl<K: Ord, V> TreeMap<K, V> {
594617

595618
/// Gets a lazy iterator that should be initialized using
596619
/// `traverse_left`/`traverse_right`/`traverse_complete`.
597-
fn mut_iter_for_traversal<'a>(&'a mut self) -> MutEntries<'a, K, V> {
620+
fn iter_mut_for_traversal<'a>(&'a mut self) -> MutEntries<'a, K, V> {
598621
MutEntries {
599622
stack: vec!(),
600-
node: mut_deref(&mut self.root),
623+
node: deref_mut(&mut self.root),
601624
remaining_min: 0,
602625
remaining_max: self.length
603626
}
604627
}
605628

629+
/// Deprecated: use `lower_bound_mut`.
630+
#[deprecated = "use lower_bound_mut"]
631+
pub fn mut_lower_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
632+
self.lower_bound_mut(k)
633+
}
634+
606635
/// Returns a lazy value iterator to the first key-value pair (with
607636
/// the value being mutable) whose key is not less than `k`.
608637
///
@@ -633,8 +662,14 @@ impl<K: Ord, V> TreeMap<K, V> {
633662
/// assert_eq!(map.find(&6), Some(&"changed"));
634663
/// assert_eq!(map.find(&8), Some(&"changed"));
635664
/// ```
636-
pub fn mut_lower_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
637-
bound_setup!(self.mut_iter_for_traversal(), k, true)
665+
pub fn lower_bound_mut<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
666+
bound_setup!(self.iter_mut_for_traversal(), k, true)
667+
}
668+
669+
/// Deprecated: use `upper_bound_mut`.
670+
#[deprecated = "use upper_bound_mut"]
671+
pub fn mut_upper_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
672+
self.upper_bound_mut(k)
638673
}
639674

640675
/// Returns a lazy iterator to the first key-value pair (with the
@@ -667,8 +702,8 @@ impl<K: Ord, V> TreeMap<K, V> {
667702
/// assert_eq!(map.find(&6), Some(&"changed"));
668703
/// assert_eq!(map.find(&8), Some(&"changed"));
669704
/// ```
670-
pub fn mut_upper_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
671-
bound_setup!(self.mut_iter_for_traversal(), k, false)
705+
pub fn upper_bound_mut<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
706+
bound_setup!(self.iter_mut_for_traversal(), k, false)
672707
}
673708
}
674709

@@ -862,7 +897,7 @@ define_iterator! {
862897
define_iterator! {
863898
MutEntries,
864899
RevMutEntries,
865-
deref = mut_deref,
900+
deref = deref_mut,
866901

867902
addr_mut = mut
868903
}
@@ -877,7 +912,7 @@ fn deref<'a, K, V>(node: &'a Option<Box<TreeNode<K, V>>>) -> *const TreeNode<K,
877912
}
878913
}
879914

880-
fn mut_deref<K, V>(x: &mut Option<Box<TreeNode<K, V>>>)
915+
fn deref_mut<K, V>(x: &mut Option<Box<TreeNode<K, V>>>)
881916
-> *mut TreeNode<K, V> {
882917
match *x {
883918
Some(ref mut n) => {
@@ -1169,6 +1204,12 @@ impl<T: Ord> TreeSet<T> {
11691204
RevSetItems{iter: self.map.rev_iter()}
11701205
}
11711206

1207+
/// Deprecated: use `into_iter`.
1208+
#[deprecated = "use into_iter"]
1209+
pub fn move_iter(self) -> MoveSetItems<T> {
1210+
self.into_iter()
1211+
}
1212+
11721213
/// Creates a consuming iterator, that is, one that moves each value out of the
11731214
/// set in ascending order. The set cannot be used after calling this.
11741215
///
@@ -1183,8 +1224,8 @@ impl<T: Ord> TreeSet<T> {
11831224
/// assert_eq!(v, vec![1, 2, 3, 4, 5]);
11841225
/// ```
11851226
#[inline]
1186-
pub fn move_iter(self) -> MoveSetItems<T> {
1187-
self.map.move_iter().map(|(value, _)| value)
1227+
pub fn into_iter(self) -> MoveSetItems<T> {
1228+
self.map.into_iter().map(|(value, _)| value)
11881229
}
11891230

11901231
/// Gets a lazy iterator pointing to the first value not less than `v` (greater or equal).
@@ -1488,7 +1529,7 @@ fn tree_find_with<'r, K, V>(node: &'r Option<Box<TreeNode<K, V>>>,
14881529
}
14891530

14901531
// See comments above tree_find_with
1491-
fn tree_find_mut_with<'r, K, V>(node: &'r mut Option<Box<TreeNode<K, V>>>,
1532+
fn tree_find_with_mut<'r, K, V>(node: &'r mut Option<Box<TreeNode<K, V>>>,
14921533
f: |&K| -> Ordering) -> Option<&'r mut V> {
14931534

14941535
let mut current = node;

src/libcollections/trie.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ impl<T> TrieMap<T> {
267267
iter
268268
}
269269

270+
/// Deprecated: use `iter_mut`.
271+
#[deprecated = "use iter_mut"]
272+
pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, T> {
273+
self.iter_mut()
274+
}
275+
270276
/// Gets an iterator over the key-value pairs in the map, with the
271277
/// ability to mutate the values.
272278
///
@@ -284,7 +290,7 @@ impl<T> TrieMap<T> {
284290
/// assert_eq!(map.find(&2), Some(&-2));
285291
/// assert_eq!(map.find(&3), Some(&-3));
286292
/// ```
287-
pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, T> {
293+
pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, T> {
288294
let mut iter = unsafe {MutEntries::new()};
289295
iter.stack[0] = self.root.children.mut_iter();
290296
iter.length = 1;
@@ -425,13 +431,19 @@ impl<T> TrieMap<T> {
425431
}
426432
// If `upper` is true then returns upper_bound else returns lower_bound.
427433
#[inline]
428-
fn mut_bound<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
434+
fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
429435
bound!(MutEntries, self = self,
430436
key = key, is_upper = upper,
431437
slice_from = mut_slice_from, iter = mut_iter,
432438
mutability = mut)
433439
}
434440

441+
/// Deprecated: use `lower_bound_mut`.
442+
#[deprecated = "use lower_bound_mut"]
443+
pub fn mut_lower_bound<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> {
444+
self.lower_bound_mut(key)
445+
}
446+
435447
/// Gets an iterator pointing to the first key-value pair whose key is not less than `key`.
436448
/// If all keys in the map are less than `key` an empty iterator is returned.
437449
///
@@ -453,8 +465,14 @@ impl<T> TrieMap<T> {
453465
/// assert_eq!(map.find(&4), Some(&"changed"));
454466
/// assert_eq!(map.find(&6), Some(&"changed"));
455467
/// ```
456-
pub fn mut_lower_bound<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> {
457-
self.mut_bound(key, false)
468+
pub fn lower_bound_mut<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> {
469+
self.bound_mut(key, false)
470+
}
471+
472+
/// Deprecated: use `upper_bound_mut`.
473+
#[deprecated = "use upper_bound_mut"]
474+
pub fn mut_upper_bound<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> {
475+
self.upper_bound_mut(key)
458476
}
459477

460478
/// Gets an iterator pointing to the first key-value pair whose key is greater than `key`.
@@ -478,8 +496,8 @@ impl<T> TrieMap<T> {
478496
/// assert_eq!(map.find(&4), Some(&"b"));
479497
/// assert_eq!(map.find(&6), Some(&"changed"));
480498
/// ```
481-
pub fn mut_upper_bound<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> {
482-
self.mut_bound(key, true)
499+
pub fn upper_bound_mut<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> {
500+
self.bound_mut(key, true)
483501
}
484502
}
485503

0 commit comments

Comments
 (0)