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]
This commit is contained in:
Aaron Turon 2014-09-14 15:57:55 -07:00
parent 828e075abd
commit d8dfe1957b
15 changed files with 293 additions and 68 deletions

View File

@ -475,9 +475,15 @@ impl<T> DList<T> {
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<T> DList<T> {
}
}
/// Deprecated: use `into_iter`.
#[deprecated = "use into_iter"]
pub fn move_iter(self) -> MoveItems<T> {
self.into_iter()
}
/// Consumes the list into an iterator yielding elements by value.
#[inline]
pub fn move_iter(self) -> MoveItems<T> {
pub fn into_iter(self) -> MoveItems<T> {
MoveItems{list: self}
}
}

View File

@ -250,6 +250,12 @@ impl<T> RingBuf<T> {
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<T> RingBuf<T> {
/// let b: &[_] = &[&mut 3, &mut 1, &mut 2];
/// assert_eq!(buf.mut_iter().collect::<Vec<&mut int>>().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);

View File

@ -260,6 +260,12 @@ impl<V> SmallIntMap<V> {
}
}
/// 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<V> SmallIntMap<V> {
/// 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<V> SmallIntMap<V> {
}
}
/// Deprecated: use `into_iter` instead.
#[deprecated = "use into_iter"]
pub fn move_iter(&mut self)
-> FilterMap<(uint, Option<V>), (uint, V),
Enumerate<vec::MoveItems<Option<V>>>> {
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<V> SmallIntMap<V> {
///
/// 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<V>), (uint, V),
Enumerate<vec::MoveItems<Option<V>>>>
{

View File

@ -226,10 +226,10 @@ impl<K: Ord, V> Map<K, V> for TreeMap<K, V> {
}
impl<K: Ord, V> MutableMap<K, V> for TreeMap<K, V> {
// 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<V> {
@ -361,6 +361,12 @@ impl<K: Ord, V> TreeMap<K, V> {
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<K: Ord, V> TreeMap<K, V> {
/// 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<K: Ord, V> TreeMap<K, V> {
/// 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<K, V> {
self.into_iter()
}
/// Gets a lazy iterator that consumes the treemap.
///
@ -434,7 +451,7 @@ impl<K: Ord, V> TreeMap<K, V> {
/// 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<K, V> {
pub fn into_iter(self) -> MoveEntries<K, V> {
let TreeMap { root: root, length: length } = self;
let stk = match root {
None => vec!(),
@ -477,6 +494,12 @@ impl<K, V> TreeMap<K, V> {
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<K, V> TreeMap<K, V> {
/// 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<K: Ord, V> TreeMap<K, V> {
/// 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<K: Ord, V> TreeMap<K, V> {
/// 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<K: Ord, V> TreeMap<K, V> {
/// 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<Box<TreeNode<K, V>>>) -> *const TreeNode<K,
}
}
fn mut_deref<K, V>(x: &mut Option<Box<TreeNode<K, V>>>)
fn deref_mut<K, V>(x: &mut Option<Box<TreeNode<K, V>>>)
-> *mut TreeNode<K, V> {
match *x {
Some(ref mut n) => {
@ -1169,6 +1204,12 @@ impl<T: Ord> TreeSet<T> {
RevSetItems{iter: self.map.rev_iter()}
}
/// Deprecated: use `into_iter`.
#[deprecated = "use into_iter"]
pub fn move_iter(self) -> MoveSetItems<T> {
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<T: Ord> TreeSet<T> {
/// assert_eq!(v, vec![1, 2, 3, 4, 5]);
/// ```
#[inline]
pub fn move_iter(self) -> MoveSetItems<T> {
self.map.move_iter().map(|(value, _)| value)
pub fn into_iter(self) -> MoveSetItems<T> {
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<Box<TreeNode<K, V>>>,
}
// See comments above tree_find_with
fn tree_find_mut_with<'r, K, V>(node: &'r mut Option<Box<TreeNode<K, V>>>,
fn tree_find_with_mut<'r, K, V>(node: &'r mut Option<Box<TreeNode<K, V>>>,
f: |&K| -> Ordering) -> Option<&'r mut V> {
let mut current = node;

View File

@ -267,6 +267,12 @@ impl<T> TrieMap<T> {
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<T> TrieMap<T> {
/// 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<T> TrieMap<T> {
}
// 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<T> TrieMap<T> {
/// 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<T> TrieMap<T> {
/// 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)
}
}

View File

@ -724,6 +724,12 @@ impl<T> Vec<T> {
}
}
/// Deprecated: use `into_iter`.
#[deprecated = "use into_iter"]
pub fn move_iter(self) -> MoveItems<T> {
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<T> Vec<T> {
/// }
/// ```
#[inline]
pub fn move_iter(self) -> MoveItems<T> {
pub fn into_iter(self) -> MoveItems<T> {
unsafe {
let iter = mem::transmute(self.as_slice().iter());
let ptr = self.ptr;
@ -822,6 +828,11 @@ impl<T> Vec<T> {
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<T> Vec<T> {
/// }
/// ```
#[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<T> Vec<T> {
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<T> Vec<T> {
/// 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<T> Vec<T> {
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<T> Vec<T> {
/// 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<T> Vec<T> {
/// 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<T> Vec<T> {
/// 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<T> Vec<T> {
/// }
/// ```
#[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)
}

View File

@ -372,17 +372,29 @@ impl<T> Option<T> {
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<T> {
self.into_iter()
}
/// Returns a consuming iterator over the possibly contained value.
#[inline]
#[unstable = "waiting for iterator conventions"]
pub fn move_iter(self) -> Item<T> {
pub fn into_iter(self) -> Item<T> {
Item{opt: self}
}

View File

@ -113,6 +113,10 @@ pub use intrinsics::set_memory;
#[unstable = "may need a different name after pending changes to pointer types"]
pub fn null<T>() -> *const T { 0 as *const T }
/// Deprecated: use `null_mut`.
#[deprecated = "use null_mut"]
pub fn mut_null<T>() -> *mut T { null_mut() }
/// Create an unsafe mutable null pointer.
///
/// # Example
@ -125,7 +129,7 @@ pub fn null<T>() -> *const T { 0 as *const T }
/// ```
#[inline]
#[unstable = "may need a different name after pending changes to pointer types"]
pub fn mut_null<T>() -> *mut T { 0 as *mut T }
pub fn null_mut<T>() -> *mut T { 0 as *mut T }
/// Zeroes out `count * size_of::<T>` bytes of memory at `dst`
#[inline]

View File

@ -500,17 +500,29 @@ impl<T, E> Result<T, E> {
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<T> {
self.into_iter()
}
/// Returns a consuming iterator over the possibly contained value.
#[inline]
#[unstable = "waiting for iterator conventions"]
pub fn move_iter(self) -> Item<T> {
pub fn into_iter(self) -> Item<T> {
Item{opt: self.ok()}
}

View File

@ -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::<T>() == 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))
}

View File

@ -32,7 +32,7 @@ trait HomogeneousTuple3<T> {
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<T> HomogeneousTuple3<T> 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()
}

View File

@ -1193,6 +1193,12 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
Entries { inner: self.table.iter() }
}
/// Deprecated: use `iter_mut`.
#[deprecated = "use iter_mut"]
pub fn mut_iter(&mut self) -> MutEntries<K, V> {
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<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
/// println!("key: {} val: {}", key, val);
/// }
/// ```
pub fn mut_iter(&mut self) -> MutEntries<K, V> {
pub fn iter_mut(&mut self) -> MutEntries<K, V> {
MutEntries { inner: self.table.mut_iter() }
}
/// Deprecated: use `into_iter`.
#[deprecated = "use into_iter"]
pub fn move_iter(self) -> MoveEntries<K, V> {
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<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
/// // Not possible with .iter()
/// let vec: Vec<(&str, int)> = map.move_iter().collect();
/// ```
pub fn move_iter(self) -> MoveEntries<K, V> {
pub fn into_iter(self) -> MoveEntries<K, V> {
MoveEntries {
inner: self.table.move_iter().map(|(_, k, v)| (k, v))
}

View File

@ -674,14 +674,14 @@ impl<K, V> RawTable<K, V> {
}
}
pub fn mut_iter(&mut self) -> MutEntries<K, V> {
pub fn iter_mut(&mut self) -> MutEntries<K, V> {
MutEntries {
iter: self.raw_buckets(),
elems_left: self.size(),
}
}
pub fn move_iter(self) -> MoveEntries<K, V> {
pub fn into_iter(self) -> MoveEntries<K, V> {
MoveEntries {
iter: self.raw_buckets(),
table: self,

View File

@ -265,7 +265,7 @@ impl<W: Writer> Writer for LineBufferedWriter<W> {
struct InternalBufferedWriter<W>(BufferedWriter<W>);
impl<W> InternalBufferedWriter<W> {
fn get_mut_ref<'a>(&'a mut self) -> &'a mut BufferedWriter<W> {
fn get_mut<'a>(&'a mut self) -> &'a mut BufferedWriter<W> {
let InternalBufferedWriter(ref mut w) = *self;
return w;
}

View File

@ -449,7 +449,7 @@ enum Flavor<T> {
#[doc(hidden)]
trait UnsafeFlavor<T> {
fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell<Flavor<T>>;
unsafe fn mut_inner<'a>(&'a self) -> &'a mut Flavor<T> {
unsafe fn inner_mut<'a>(&'a self) -> &'a mut Flavor<T> {
&mut *self.inner_unsafe().get()
}
unsafe fn inner<'a>(&'a self) -> &'a Flavor<T> {