From d8dfe1957b6541de8fe2797e248fe4bd2fac02d9 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Sun, 14 Sep 2014 15:57:55 -0700 Subject: [PATCH] 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] --- src/libcollections/dlist.rs | 15 ++++- src/libcollections/ringbuf.rs | 8 ++- src/libcollections/smallintmap.rs | 18 ++++- src/libcollections/treemap.rs | 79 ++++++++++++++++------ src/libcollections/trie.rs | 30 +++++++-- src/libcollections/vec.rs | 56 ++++++++++++++-- src/libcore/option.rs | 16 ++++- src/libcore/ptr.rs | 6 +- src/libcore/result.rs | 16 ++++- src/libcore/slice.rs | 89 ++++++++++++++++++++----- src/librustc/middle/subst.rs | 4 +- src/libstd/collections/hashmap/map.rs | 16 ++++- src/libstd/collections/hashmap/table.rs | 4 +- src/libstd/io/buffered.rs | 2 +- src/libsync/comm/mod.rs | 2 +- 15 files changed, 293 insertions(+), 68 deletions(-) diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 0ed946aa947db..cf5c1eed15cd0 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -475,9 +475,15 @@ impl DList { Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail} } + /// Deprecated: use `iter_mut`. + #[deprecated = "use iter_mut"] + pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> { + self.iter_mut() + } + /// Provides a forward iterator with mutable references. #[inline] - pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> { + pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> { let head_raw = match self.list_head { Some(ref mut h) => Rawlink::some(&mut **h), None => Rawlink::none(), @@ -490,10 +496,15 @@ impl DList { } } + /// Deprecated: use `into_iter`. + #[deprecated = "use into_iter"] + pub fn move_iter(self) -> MoveItems { + self.into_iter() + } /// Consumes the list into an iterator yielding elements by value. #[inline] - pub fn move_iter(self) -> MoveItems { + pub fn into_iter(self) -> MoveItems { MoveItems{list: self} } } diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index aa745ef39ee13..a3dc1d3003104 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -250,6 +250,12 @@ impl RingBuf { Items{index: 0, rindex: self.nelts, lo: self.lo, elts: self.elts.as_slice()} } + /// Deprecated: use `iter_mut` + #[deprecated = "use iter_mut"] + pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> { + self.iter_mut() + } + /// Returns a front-to-back iterator which returns mutable references. /// /// # Example @@ -267,7 +273,7 @@ impl RingBuf { /// let b: &[_] = &[&mut 3, &mut 1, &mut 2]; /// assert_eq!(buf.mut_iter().collect::>().as_slice(), b); /// ``` - pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> { + pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> { let start_index = raw_index(self.lo, self.elts.len(), 0); let end_index = raw_index(self.lo, self.elts.len(), self.nelts); diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index dd3a639aeac78..aac34bfd15581 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -260,6 +260,12 @@ impl SmallIntMap { } } + /// Deprecated: use `iter_mut` + #[deprecated = "use iter_mut"] + pub fn mut_iter<'r>(&'r mut self) -> MutEntries<'r, V> { + self.iter_mut() + } + /// Returns an iterator visiting all key-value pairs in ascending order by the keys, /// with mutable references to the values. /// The iterator's element type is `(uint, &'r mut V)`. @@ -282,7 +288,7 @@ impl SmallIntMap { /// assert_eq!(value, &"x"); /// } /// ``` - pub fn mut_iter<'r>(&'r mut self) -> MutEntries<'r, V> { + pub fn iter_mut<'r>(&'r mut self) -> MutEntries<'r, V> { MutEntries { front: 0, back: self.v.len(), @@ -290,6 +296,14 @@ impl SmallIntMap { } } + /// Deprecated: use `into_iter` instead. + #[deprecated = "use into_iter"] + pub fn move_iter(&mut self) + -> FilterMap<(uint, Option), (uint, V), + Enumerate>>> { + self.into_iter() + } + /// Returns an iterator visiting all key-value pairs in ascending order by /// the keys, emptying (but not consuming) the original `SmallIntMap`. /// The iterator's element type is `(uint, &'r V)`. @@ -309,7 +323,7 @@ impl SmallIntMap { /// /// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]); /// ``` - pub fn move_iter(&mut self) + pub fn into_iter(&mut self) -> FilterMap<(uint, Option), (uint, V), Enumerate>>> { diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index 354edae473fd5..0a7c84b5c0c55 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -226,10 +226,10 @@ impl Map for TreeMap { } impl MutableMap for TreeMap { - // See comments on def_tree_find_mut_with + // See comments on tree_find_with_mut #[inline] fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V> { - tree_find_mut_with(&mut self.root, |x| key.cmp(x)) + tree_find_with_mut(&mut self.root, |x| key.cmp(x)) } fn swap(&mut self, key: K, value: V) -> Option { @@ -361,6 +361,12 @@ impl TreeMap { RevEntries{iter: self.iter()} } + /// Deprecated: use `iter_mut`. + #[deprecated = "use iter_mut"] + pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, K, V> { + self.iter_mut() + } + /// Gets a lazy forward iterator over the key-value pairs in the /// map, with the values being mutable. /// @@ -383,15 +389,21 @@ impl TreeMap { /// assert_eq!(map.find(&"b"), Some(&12)); /// assert_eq!(map.find(&"c"), Some(&3)); /// ``` - pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, K, V> { + pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> { MutEntries { stack: vec!(), - node: mut_deref(&mut self.root), + node: deref_mut(&mut self.root), remaining_min: self.length, remaining_max: self.length } } + /// Deprecated: use `rev_iter_mut`. + #[deprecated = "use rev_iter_mut"] + pub fn mut_rev_iter<'a>(&'a mut self) -> RevMutEntries<'a, K, V> { + self.rev_iter_mut() + } + /// Gets a lazy reverse iterator over the key-value pairs in the /// map, with the values being mutable. /// @@ -414,10 +426,15 @@ impl TreeMap { /// assert_eq!(map.find(&"b"), Some(&12)); /// assert_eq!(map.find(&"c"), Some(&13)); /// ``` - pub fn mut_rev_iter<'a>(&'a mut self) -> RevMutEntries<'a, K, V> { + pub fn rev_iter_mut<'a>(&'a mut self) -> RevMutEntries<'a, K, V> { RevMutEntries{iter: self.mut_iter()} } + /// Deprecated: use `into_iter`. + #[depreated = "use into_iter"] + pub fn move_iter(self) -> MoveEntries { + self.into_iter() + } /// Gets a lazy iterator that consumes the treemap. /// @@ -434,7 +451,7 @@ impl TreeMap { /// let vec: Vec<(&str, int)> = map.move_iter().collect(); /// assert_eq!(vec, vec![("a", 1), ("b", 2), ("c", 3)]); /// ``` - pub fn move_iter(self) -> MoveEntries { + pub fn into_iter(self) -> MoveEntries { let TreeMap { root: root, length: length } = self; let stk = match root { None => vec!(), @@ -477,6 +494,12 @@ impl TreeMap { tree_find_with(&self.root, f) } + /// Deprecated: use `find_with_mut`. + #[deprecated = "use find_with_mut"] + pub fn find_mut_with<'a>(&'a mut self, f:|&K| -> Ordering) -> Option<&'a mut V> { + self.find_with_mut(f) + } + /// Returns the value for which `f(key)` returns `Equal`. `f` is invoked /// with current key and guides tree navigation. That means `f` should /// be aware of natural ordering of the tree. @@ -497,8 +520,8 @@ impl TreeMap { /// assert_eq!(t.find(&"User-Agent"), Some(&new_ua)); /// ``` #[inline] - pub fn find_mut_with<'a>(&'a mut self, f:|&K| -> Ordering) -> Option<&'a mut V> { - tree_find_mut_with(&mut self.root, f) + pub fn find_with_mut<'a>(&'a mut self, f:|&K| -> Ordering) -> Option<&'a mut V> { + tree_find_with_mut(&mut self.root, f) } } @@ -594,15 +617,21 @@ impl TreeMap { /// Gets a lazy iterator that should be initialized using /// `traverse_left`/`traverse_right`/`traverse_complete`. - fn mut_iter_for_traversal<'a>(&'a mut self) -> MutEntries<'a, K, V> { + fn iter_mut_for_traversal<'a>(&'a mut self) -> MutEntries<'a, K, V> { MutEntries { stack: vec!(), - node: mut_deref(&mut self.root), + node: deref_mut(&mut self.root), remaining_min: 0, remaining_max: self.length } } + /// Deprecated: use `lower_bound_mut`. + #[deprecated = "use lower_bound_mut"] + pub fn mut_lower_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> { + self.lower_bound_mut(k) + } + /// Returns a lazy value iterator to the first key-value pair (with /// the value being mutable) whose key is not less than `k`. /// @@ -633,8 +662,14 @@ impl TreeMap { /// assert_eq!(map.find(&6), Some(&"changed")); /// assert_eq!(map.find(&8), Some(&"changed")); /// ``` - pub fn mut_lower_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> { - bound_setup!(self.mut_iter_for_traversal(), k, true) + pub fn lower_bound_mut<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> { + bound_setup!(self.iter_mut_for_traversal(), k, true) + } + + /// Deprecated: use `upper_bound_mut`. + #[deprecated = "use upper_bound_mut"] + pub fn mut_upper_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> { + self.upper_bound_mut(k) } /// Returns a lazy iterator to the first key-value pair (with the @@ -667,8 +702,8 @@ impl TreeMap { /// assert_eq!(map.find(&6), Some(&"changed")); /// assert_eq!(map.find(&8), Some(&"changed")); /// ``` - pub fn mut_upper_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> { - bound_setup!(self.mut_iter_for_traversal(), k, false) + pub fn upper_bound_mut<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> { + bound_setup!(self.iter_mut_for_traversal(), k, false) } } @@ -862,7 +897,7 @@ define_iterator! { define_iterator! { MutEntries, RevMutEntries, - deref = mut_deref, + deref = deref_mut, addr_mut = mut } @@ -877,7 +912,7 @@ fn deref<'a, K, V>(node: &'a Option>>) -> *const TreeNode(x: &mut Option>>) +fn deref_mut(x: &mut Option>>) -> *mut TreeNode { match *x { Some(ref mut n) => { @@ -1169,6 +1204,12 @@ impl TreeSet { RevSetItems{iter: self.map.rev_iter()} } + /// Deprecated: use `into_iter`. + #[deprecated = "use into_iter"] + pub fn move_iter(self) -> MoveSetItems { + self.into_iter() + } + /// Creates a consuming iterator, that is, one that moves each value out of the /// set in ascending order. The set cannot be used after calling this. /// @@ -1183,8 +1224,8 @@ impl TreeSet { /// assert_eq!(v, vec![1, 2, 3, 4, 5]); /// ``` #[inline] - pub fn move_iter(self) -> MoveSetItems { - self.map.move_iter().map(|(value, _)| value) + pub fn into_iter(self) -> MoveSetItems { + self.map.into_iter().map(|(value, _)| value) } /// 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>>, } // See comments above tree_find_with -fn tree_find_mut_with<'r, K, V>(node: &'r mut Option>>, +fn tree_find_with_mut<'r, K, V>(node: &'r mut Option>>, f: |&K| -> Ordering) -> Option<&'r mut V> { let mut current = node; diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 7d60d3a85e128..f447bcba917a8 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -267,6 +267,12 @@ impl TrieMap { iter } + /// Deprecated: use `iter_mut`. + #[deprecated = "use iter_mut"] + pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, T> { + self.iter_mut() + } + /// Gets an iterator over the key-value pairs in the map, with the /// ability to mutate the values. /// @@ -284,7 +290,7 @@ impl TrieMap { /// assert_eq!(map.find(&2), Some(&-2)); /// assert_eq!(map.find(&3), Some(&-3)); /// ``` - pub fn mut_iter<'a>(&'a mut self) -> MutEntries<'a, T> { + pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, T> { let mut iter = unsafe {MutEntries::new()}; iter.stack[0] = self.root.children.mut_iter(); iter.length = 1; @@ -425,13 +431,19 @@ impl TrieMap { } // If `upper` is true then returns upper_bound else returns lower_bound. #[inline] - fn mut_bound<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> { + fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> { bound!(MutEntries, self = self, key = key, is_upper = upper, slice_from = mut_slice_from, iter = mut_iter, mutability = mut) } + /// Deprecated: use `lower_bound_mut`. + #[deprecated = "use lower_bound_mut"] + pub fn mut_lower_bound<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> { + self.lower_bound_mut(key) + } + /// Gets an iterator pointing to the first key-value pair whose key is not less than `key`. /// If all keys in the map are less than `key` an empty iterator is returned. /// @@ -453,8 +465,14 @@ impl TrieMap { /// assert_eq!(map.find(&4), Some(&"changed")); /// assert_eq!(map.find(&6), Some(&"changed")); /// ``` - pub fn mut_lower_bound<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> { - self.mut_bound(key, false) + pub fn lower_bound_mut<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> { + self.bound_mut(key, false) + } + + /// Deprecated: use `upper_bound_mut`. + #[deprecated = "use upper_bound_mut"] + pub fn mut_upper_bound<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> { + self.upper_bound_mut(key) } /// Gets an iterator pointing to the first key-value pair whose key is greater than `key`. @@ -478,8 +496,8 @@ impl TrieMap { /// assert_eq!(map.find(&4), Some(&"b")); /// assert_eq!(map.find(&6), Some(&"changed")); /// ``` - pub fn mut_upper_bound<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> { - self.mut_bound(key, true) + pub fn upper_bound_mut<'a>(&'a mut self, key: uint) -> MutEntries<'a, T> { + self.bound_mut(key, true) } } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 5215e8aaab88f..3557390ef9651 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -724,6 +724,12 @@ impl Vec { } } + /// Deprecated: use `into_iter`. + #[deprecated = "use into_iter"] + pub fn move_iter(self) -> MoveItems { + self.into_iter() + } + /// Creates a consuming iterator, that is, one that moves each /// value out of the vector (from start to end). The vector cannot /// be used after calling this. @@ -738,7 +744,7 @@ impl Vec { /// } /// ``` #[inline] - pub fn move_iter(self) -> MoveItems { + pub fn into_iter(self) -> MoveItems { unsafe { let iter = mem::transmute(self.as_slice().iter()); let ptr = self.ptr; @@ -822,6 +828,11 @@ impl Vec { self.as_slice().iter() } + /// Deprecated: use `iter_mut`. + #[deprecated = "use iter_mut"] + pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a,T> { + self.iter_mut() + } /// Returns an iterator over mutable references to the elements of the /// vector in order. @@ -835,7 +846,7 @@ impl Vec { /// } /// ``` #[inline] - pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a,T> { + pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a,T> { self.as_mut_slice().mut_iter() } @@ -927,6 +938,12 @@ impl Vec { self.as_slice().last() } + /// Deprecated: use `last_mut`. + #[deprecated = "use last_mut"] + pub fn mut_last<'a>(&'a mut self) -> Option<&'a mut T> { + self.last_mut() + } + /// Returns a mutable reference to the last element of a vector, or `None` /// if it is empty. /// @@ -938,7 +955,7 @@ impl Vec { /// assert_eq!(vec, vec![1i, 2, 4]); /// ``` #[inline] - pub fn mut_last<'a>(&'a mut self) -> Option<&'a mut T> { + pub fn last_mut<'a>(&'a mut self) -> Option<&'a mut T> { self.as_mut_slice().mut_last() } @@ -1105,6 +1122,13 @@ impl Vec { self.extend(other.move_iter()); } + /// Deprecated: use `slice_mut`. + #[deprecated = "use slice_mut"] + pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint) + -> &'a mut [T] { + self.slice_mut(start, end) + } + /// Returns a mutable slice of `self` between `start` and `end`. /// /// # Failure @@ -1119,11 +1143,17 @@ impl Vec { /// assert!(vec.mut_slice(0, 2) == [1, 2]); /// ``` #[inline] - pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint) + pub fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] { self.as_mut_slice().mut_slice(start, end) } + /// Deprecated: use "slice_from_mut". + #[deprecated = "use slice_from_mut"] + pub fn mut_slice_from<'a>(&'a mut self, start: uint) -> &'a mut [T] { + self.slice_from_mut(start) + } + /// Returns a mutable slice of `self` from `start` to the end of the `Vec`. /// /// # Failure @@ -1137,10 +1167,16 @@ impl Vec { /// assert!(vec.mut_slice_from(2) == [3, 4]); /// ``` #[inline] - pub fn mut_slice_from<'a>(&'a mut self, start: uint) -> &'a mut [T] { + pub fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] { self.as_mut_slice().mut_slice_from(start) } + /// Deprecated: use `slice_to_mut`. + #[deprecated = "use slice_to_mut"] + pub fn mut_slice_to<'a>(&'a mut self, end: uint) -> &'a mut [T] { + self.slice_to_mut(end) + } + /// Returns a mutable slice of `self` from the start of the `Vec` to `end`. /// /// # Failure @@ -1154,10 +1190,16 @@ impl Vec { /// assert!(vec.mut_slice_to(2) == [1, 2]); /// ``` #[inline] - pub fn mut_slice_to<'a>(&'a mut self, end: uint) -> &'a mut [T] { + pub fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] { self.as_mut_slice().mut_slice_to(end) } + /// Deprecated: use `split_at_mut`. + #[deprecated = "use split_at_mut"] + pub fn mut_split_at<'a>(&'a mut self, mid: uint) -> (&'a mut [T], &'a mut [T]) { + self.split_at_mut(mid) + } + /// Returns a pair of mutable slices that divides the `Vec` at an index. /// /// The first will contain all indices from `[0, mid)` (excluding @@ -1193,7 +1235,7 @@ impl Vec { /// } /// ``` #[inline] - pub fn mut_split_at<'a>(&'a mut self, mid: uint) -> (&'a mut [T], &'a mut [T]) { + pub fn split_at_mut<'a>(&'a mut self, mid: uint) -> (&'a mut [T], &'a mut [T]) { self.as_mut_slice().mut_split_at(mid) } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 537d78a67feb2..cd6e8f3e666e1 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -372,17 +372,29 @@ impl Option { Item{opt: self.as_ref()} } + /// Deprecated: use `iter_mut` + #[deprecated = "use iter_mut"] + pub fn mut_iter<'r>(&'r mut self) -> Item<&'r mut T> { + self.iter_mut() + } + /// Returns a mutable iterator over the possibly contained value. #[inline] #[unstable = "waiting for iterator conventions"] - pub fn mut_iter<'r>(&'r mut self) -> Item<&'r mut T> { + pub fn iter_mut<'r>(&'r mut self) -> Item<&'r mut T> { Item{opt: self.as_mut()} } + /// Deprecated: use `into_iter`. + #[deprecated = "use into_iter"] + pub fn move_iter(self) -> Item { + self.into_iter() + } + /// Returns a consuming iterator over the possibly contained value. #[inline] #[unstable = "waiting for iterator conventions"] - pub fn move_iter(self) -> Item { + pub fn into_iter(self) -> Item { Item{opt: self} } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index d1bea25dded41..42416a640bf65 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -113,6 +113,10 @@ pub use intrinsics::set_memory; #[unstable = "may need a different name after pending changes to pointer types"] pub fn null() -> *const T { 0 as *const T } +/// Deprecated: use `null_mut`. +#[deprecated = "use null_mut"] +pub fn mut_null() -> *mut T { null_mut() } + /// Create an unsafe mutable null pointer. /// /// # Example @@ -125,7 +129,7 @@ pub fn null() -> *const T { 0 as *const T } /// ``` #[inline] #[unstable = "may need a different name after pending changes to pointer types"] -pub fn mut_null() -> *mut T { 0 as *mut T } +pub fn null_mut() -> *mut T { 0 as *mut T } /// Zeroes out `count * size_of::` bytes of memory at `dst` #[inline] diff --git a/src/libcore/result.rs b/src/libcore/result.rs index bf351ecc89b1f..426ae8f09298c 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -500,17 +500,29 @@ impl Result { Item{opt: self.as_ref().ok()} } + /// Deprecated: use `iter_mut`. + #[deprecated = "use iter_mut"] + pub fn mut_iter<'r>(&'r mut self) -> Item<&'r mut T> { + self.iter_mut() + } + /// Returns a mutable iterator over the possibly contained value. #[inline] #[unstable = "waiting for iterator conventions"] - pub fn mut_iter<'r>(&'r mut self) -> Item<&'r mut T> { + pub fn iter_mut<'r>(&'r mut self) -> Item<&'r mut T> { Item{opt: self.as_mut().ok()} } + /// Deprecated: `use into_iter`. + #[deprecated = "use into_iter"] + pub fn move_iter(self) -> Item { + self.into_iter() + } + /// Returns a consuming iterator over the possibly contained value. #[inline] #[unstable = "waiting for iterator conventions"] - pub fn move_iter(self) -> Item { + pub fn into_iter(self) -> Item { Item{opt: self.ok()} } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index cc2b01e3bb58b..05b0c1e4f70ba 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -486,38 +486,80 @@ pub trait MutableSlice<'a, T> { /// Primarily intended for getting a &mut [T] from a [T, ..N]. fn as_mut_slice(self) -> &'a mut [T]; + /// Deprecated: use `slice_mut`. + #[deprecated = "use slice_mut"] + fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] { + self.slice_mut(start, end) + } + /// Returns a mutable subslice spanning the interval [`start`, `end`). /// /// Fails when the end of the new slice lies beyond the end of the /// original slice (i.e. when `end > self.len()`) or when `start > end`. /// /// Slicing with `start` equal to `end` yields an empty slice. - fn mut_slice(self, start: uint, end: uint) -> &'a mut [T]; + fn slice_mut(self, start: uint, end: uint) -> &'a mut [T]; + + /// Deprecated: use `slice_from_mut`. + #[deprecated = "use slice_from_mut"] + fn mut_slice_from(self, start: uint) -> &'a mut [T] { + self.slice_from_mut(start) + } /// Returns a mutable subslice from `start` to the end of the slice. /// /// Fails when `start` is strictly greater than the length of the original slice. /// /// Slicing from `self.len()` yields an empty slice. - fn mut_slice_from(self, start: uint) -> &'a mut [T]; + fn slice_from_mut(self, start: uint) -> &'a mut [T]; + + /// Deprecated: use `slice_to_mut`. + #[deprecated = "use slice_to_mut"] + fn mut_slice_to(self, end: uint) -> &'a mut [T] { + self.slice_to_mut(end) + } /// Returns a mutable subslice from the start of the slice to `end`. /// /// Fails when `end` is strictly greater than the length of the original slice. /// /// Slicing to `0` yields an empty slice. - fn mut_slice_to(self, end: uint) -> &'a mut [T]; + fn slice_to_mut(self, end: uint) -> &'a mut [T]; + + /// Deprecated: use `iter_mut`. + #[deprecated = "use iter_mut"] + fn mut_iter(self) -> MutItems<'a, T> { + self.iter_mut() + } /// Returns an iterator that allows modifying each value - fn mut_iter(self) -> MutItems<'a, T>; + fn iter_mut(self) -> MutItems<'a, T>; + + /// Deprecated: use `last_mut`. + #[deprecated = "use last_mut"] + fn mut_last(self) -> Option<&'a mut T> { + self.last_mut() + } /// Returns a mutable pointer to the last item in the vector. - fn mut_last(self) -> Option<&'a mut T>; + fn last_mut(self) -> Option<&'a mut T>; + + /// Deprecated: use `split_mut`. + #[deprecated = "use split_mut"] + fn mut_split(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T> { + self.split_mut(pred) + } /// Returns an iterator over the mutable subslices of the vector /// which are separated by elements that match `pred`. The /// matched element is not contained in the subslices. - fn mut_split(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T>; + fn split_mut(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T>; + + /// Deprecated: use `chunks_mut`. + #[deprecated = "use chunks_mut"] + fn mut_chunks(self, chunk_size: uint) -> MutChunks<'a, T> { + self.chunks_mut(chunk_size) + } /** * Returns an iterator over `chunk_size` elements of the vector at a time. @@ -529,7 +571,7 @@ pub trait MutableSlice<'a, T> { * * Fails if `chunk_size` is 0. */ - fn mut_chunks(self, chunk_size: uint) -> MutChunks<'a, T>; + fn chunks_mut(self, chunk_size: uint) -> MutChunks<'a, T>; /** * Returns a mutable reference to the first element in this slice @@ -587,6 +629,11 @@ pub trait MutableSlice<'a, T> { /// ``` fn swap(self, a: uint, b: uint); + /// Deprecated: use `split_at_mut`. + #[deprecated = "use split_at_mut"] + fn mut_split_at(self, mid: uint) -> (&'a mut [T], &'a mut [T]) { + self.split_at_mut(mid) + } /// Divides one `&mut` into two at an index. /// @@ -620,7 +667,7 @@ pub trait MutableSlice<'a, T> { /// assert!(right == &mut []); /// } /// ``` - fn mut_split_at(self, mid: uint) -> (&'a mut [T], &'a mut [T]); + fn split_at_mut(self, mid: uint) -> (&'a mut [T], &'a mut [T]); /// Reverse the order of elements in a vector, in place. /// @@ -633,8 +680,14 @@ pub trait MutableSlice<'a, T> { /// ``` fn reverse(self); + /// Deprecated: use `unsafe_mut`. + #[deprecated = "use unsafe_mut"] + unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T { + self.unsafe_mut(index) + } + /// Returns an unsafe mutable pointer to the element in index - unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T; + unsafe fn unsafe_mut(self, index: uint) -> &'a mut T; /// Return an unsafe mutable pointer to the vector's buffer. /// @@ -701,7 +754,7 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { #[inline] fn as_mut_slice(self) -> &'a mut [T] { self } - fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] { + fn slice_mut(self, start: uint, end: uint) -> &'a mut [T] { assert!(start <= end); assert!(end <= self.len()); unsafe { @@ -713,18 +766,18 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { } #[inline] - fn mut_slice_from(self, start: uint) -> &'a mut [T] { + fn slice_from_mut(self, start: uint) -> &'a mut [T] { let len = self.len(); self.mut_slice(start, len) } #[inline] - fn mut_slice_to(self, end: uint) -> &'a mut [T] { + fn slice_to_mut(self, end: uint) -> &'a mut [T] { self.mut_slice(0, end) } #[inline] - fn mut_split_at(self, mid: uint) -> (&'a mut [T], &'a mut [T]) { + fn split_at_mut(self, mid: uint) -> (&'a mut [T], &'a mut [T]) { unsafe { let len = self.len(); let self2: &'a mut [T] = mem::transmute_copy(&self); @@ -733,7 +786,7 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { } #[inline] - fn mut_iter(self) -> MutItems<'a, T> { + fn iter_mut(self) -> MutItems<'a, T> { unsafe { let p = self.as_mut_ptr(); if mem::size_of::() == 0 { @@ -751,19 +804,19 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { } #[inline] - fn mut_last(self) -> Option<&'a mut T> { + fn last_mut(self) -> Option<&'a mut T> { let len = self.len(); if len == 0 { return None; } Some(&mut self[len - 1]) } #[inline] - fn mut_split(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T> { + fn split_mut(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T> { MutSplits { v: self, pred: pred, finished: false } } #[inline] - fn mut_chunks(self, chunk_size: uint) -> MutChunks<'a, T> { + fn chunks_mut(self, chunk_size: uint) -> MutChunks<'a, T> { assert!(chunk_size > 0); MutChunks { v: self, chunk_size: chunk_size } } @@ -817,7 +870,7 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { } #[inline] - unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T { + unsafe fn unsafe_mut(self, index: uint) -> &'a mut T { transmute((self.repr().data as *mut T).offset(index as int)) } diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index d7e6fd18ed563..5559f222fe219 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -32,7 +32,7 @@ trait HomogeneousTuple3 { fn as_slice<'a>(&'a self) -> &'a [T]; fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T]; fn iter<'a>(&'a self) -> Items<'a, T>; - fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T>; + fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T>; fn get<'a>(&'a self, index: uint) -> Option<&'a T>; fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut T>; } @@ -63,7 +63,7 @@ impl HomogeneousTuple3 for (T, T, T) { slice.iter() } - fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> { + fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> { self.as_mut_slice().mut_iter() } diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index a50c6a59f7e04..4a58f4e75de70 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -1193,6 +1193,12 @@ impl, V, S, H: Hasher> HashMap { Entries { inner: self.table.iter() } } + /// Deprecated: use `iter_mut`. + #[deprecated = "use iter_mut"] + pub fn mut_iter(&mut self) -> MutEntries { + self.iter_mut() + } + /// An iterator visiting all key-value pairs in arbitrary order, /// with mutable references to the values. /// Iterator element type is `(&'a K, &'a mut V)`. @@ -1216,10 +1222,16 @@ impl, V, S, H: Hasher> HashMap { /// println!("key: {} val: {}", key, val); /// } /// ``` - pub fn mut_iter(&mut self) -> MutEntries { + pub fn iter_mut(&mut self) -> MutEntries { MutEntries { inner: self.table.mut_iter() } } + /// Deprecated: use `into_iter`. + #[deprecated = "use into_iter"] + pub fn move_iter(self) -> MoveEntries { + self.into_iter() + } + /// Creates a consuming iterator, that is, one that moves each key-value /// pair out of the map in arbitrary order. The map cannot be used after /// calling this. @@ -1237,7 +1249,7 @@ impl, V, S, H: Hasher> HashMap { /// // Not possible with .iter() /// let vec: Vec<(&str, int)> = map.move_iter().collect(); /// ``` - pub fn move_iter(self) -> MoveEntries { + pub fn into_iter(self) -> MoveEntries { MoveEntries { inner: self.table.move_iter().map(|(_, k, v)| (k, v)) } diff --git a/src/libstd/collections/hashmap/table.rs b/src/libstd/collections/hashmap/table.rs index 2edb8cd092e0c..33e760f11cea4 100644 --- a/src/libstd/collections/hashmap/table.rs +++ b/src/libstd/collections/hashmap/table.rs @@ -674,14 +674,14 @@ impl RawTable { } } - pub fn mut_iter(&mut self) -> MutEntries { + pub fn iter_mut(&mut self) -> MutEntries { MutEntries { iter: self.raw_buckets(), elems_left: self.size(), } } - pub fn move_iter(self) -> MoveEntries { + pub fn into_iter(self) -> MoveEntries { MoveEntries { iter: self.raw_buckets(), table: self, diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 0c63f1a901f5a..76f86d66ff546 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -265,7 +265,7 @@ impl Writer for LineBufferedWriter { struct InternalBufferedWriter(BufferedWriter); impl InternalBufferedWriter { - fn get_mut_ref<'a>(&'a mut self) -> &'a mut BufferedWriter { + fn get_mut<'a>(&'a mut self) -> &'a mut BufferedWriter { let InternalBufferedWriter(ref mut w) = *self; return w; } diff --git a/src/libsync/comm/mod.rs b/src/libsync/comm/mod.rs index 9177fa4a6b446..e46f52b3ad7b9 100644 --- a/src/libsync/comm/mod.rs +++ b/src/libsync/comm/mod.rs @@ -449,7 +449,7 @@ enum Flavor { #[doc(hidden)] trait UnsafeFlavor { fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell>; - unsafe fn mut_inner<'a>(&'a self) -> &'a mut Flavor { + unsafe fn inner_mut<'a>(&'a self) -> &'a mut Flavor { &mut *self.inner_unsafe().get() } unsafe fn inner<'a>(&'a self) -> &'a Flavor {