mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 08:53:35 +00:00
std: Change RandomAccessIterator to use &mut self
Many iterators go through a closure when dealing with the `idx` method, which are invalid after the previous change (closures cannot be invoked through a `&` pointer). This commit alters the `fn idx` method on the RandomAccessIterator to take `&mut self` rather than `&self`. [breaking-change]
This commit is contained in:
parent
159a10da4c
commit
f4083a2245
@ -632,7 +632,7 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<bool> {
|
fn idx(&mut self, index: uint) -> Option<bool> {
|
||||||
if index >= self.indexable() {
|
if index >= self.indexable() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -272,7 +272,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
|
|||||||
fn indexable(&self) -> uint { self.rindex - self.index }
|
fn indexable(&self) -> uint { self.rindex - self.index }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, j: uint) -> Option<&'a T> {
|
fn idx(&mut self, j: uint) -> Option<&'a T> {
|
||||||
if j >= self.indexable() {
|
if j >= self.indexable() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -703,7 +703,7 @@ pub trait RandomAccessIterator<A>: Iterator<A> {
|
|||||||
fn indexable(&self) -> uint;
|
fn indexable(&self) -> uint;
|
||||||
|
|
||||||
/// Return an element at an index
|
/// Return an element at an index
|
||||||
fn idx(&self, index: uint) -> Option<A>;
|
fn idx(&mut self, index: uint) -> Option<A>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator that knows its exact length
|
/// An iterator that knows its exact length
|
||||||
@ -771,8 +771,9 @@ impl<A, T: DoubleEndedIterator<A> + RandomAccessIterator<A>> RandomAccessIterato
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn indexable(&self) -> uint { self.iter.indexable() }
|
fn indexable(&self) -> uint { self.iter.indexable() }
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<A> {
|
fn idx(&mut self, index: uint) -> Option<A> {
|
||||||
self.iter.idx(self.indexable() - index - 1)
|
let amt = self.indexable();
|
||||||
|
self.iter.idx(amt - index - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1071,7 +1072,7 @@ impl<A, T: Clone + RandomAccessIterator<A>> RandomAccessIterator<A> for Cycle<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<A> {
|
fn idx(&mut self, index: uint) -> Option<A> {
|
||||||
let liter = self.iter.indexable();
|
let liter = self.iter.indexable();
|
||||||
let lorig = self.orig.indexable();
|
let lorig = self.orig.indexable();
|
||||||
if lorig == 0 {
|
if lorig == 0 {
|
||||||
@ -1143,7 +1144,7 @@ for Chain<T, U> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<A> {
|
fn idx(&mut self, index: uint) -> Option<A> {
|
||||||
let len = self.a.indexable();
|
let len = self.a.indexable();
|
||||||
if index < len {
|
if index < len {
|
||||||
self.a.idx(index)
|
self.a.idx(index)
|
||||||
@ -1221,7 +1222,7 @@ RandomAccessIterator<(A, B)> for Zip<T, U> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<(A, B)> {
|
fn idx(&mut self, index: uint) -> Option<(A, B)> {
|
||||||
match self.a.idx(index) {
|
match self.a.idx(index) {
|
||||||
None => None,
|
None => None,
|
||||||
Some(x) => match self.b.idx(index) {
|
Some(x) => match self.b.idx(index) {
|
||||||
@ -1276,8 +1277,9 @@ impl<'a, A, B, T: RandomAccessIterator<A>> RandomAccessIterator<B> for Map<'a, A
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<B> {
|
fn idx(&mut self, index: uint) -> Option<B> {
|
||||||
self.do_map(self.iter.idx(index))
|
let elt = self.iter.idx(index);
|
||||||
|
self.do_map(elt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1415,7 +1417,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<(uint, A)> for Enumerat
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<(uint, A)> {
|
fn idx(&mut self, index: uint) -> Option<(uint, A)> {
|
||||||
match self.iter.idx(index) {
|
match self.iter.idx(index) {
|
||||||
Some(a) => Some((self.count + index, a)),
|
Some(a) => Some((self.count + index, a)),
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -1600,7 +1602,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Skip<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<A> {
|
fn idx(&mut self, index: uint) -> Option<A> {
|
||||||
if index >= self.indexable() {
|
if index >= self.indexable() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -1649,7 +1651,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Take<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<A> {
|
fn idx(&mut self, index: uint) -> Option<A> {
|
||||||
if index >= self.n {
|
if index >= self.n {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -1799,7 +1801,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Fuse<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<A> {
|
fn idx(&mut self, index: uint) -> Option<A> {
|
||||||
self.iter.idx(index)
|
self.iter.idx(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1862,8 +1864,9 @@ for Inspect<'a, A, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<A> {
|
fn idx(&mut self, index: uint) -> Option<A> {
|
||||||
self.do_inspect(self.iter.idx(index))
|
let element = self.iter.idx(index);
|
||||||
|
self.do_inspect(element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2164,7 +2167,7 @@ impl<A: Clone> RandomAccessIterator<A> for Repeat<A> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn indexable(&self) -> uint { uint::MAX }
|
fn indexable(&self) -> uint { uint::MAX }
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, _: uint) -> Option<A> { Some(self.element.clone()) }
|
fn idx(&mut self, _: uint) -> Option<A> { Some(self.element.clone()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Functions for lexicographical ordering of sequences.
|
/// Functions for lexicographical ordering of sequences.
|
||||||
|
@ -489,7 +489,7 @@ impl<'a, T> RandomAccessIterator<&'a [T]> for Chunks<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<&'a [T]> {
|
fn idx(&mut self, index: uint) -> Option<&'a [T]> {
|
||||||
if index < self.indexable() {
|
if index < self.indexable() {
|
||||||
let lo = index * self.size;
|
let lo = index * self.size;
|
||||||
let mut hi = lo + self.size;
|
let mut hi = lo + self.size;
|
||||||
@ -2095,7 +2095,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, index: uint) -> Option<&'a T> {
|
fn idx(&mut self, index: uint) -> Option<&'a T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if index < self.indexable() {
|
if index < self.indexable() {
|
||||||
transmute(self.ptr.offset(index as int))
|
transmute(self.ptr.offset(index as int))
|
||||||
|
Loading…
Reference in New Issue
Block a user