@@ -2125,7 +2125,12 @@ macro_rules! iterator {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn size_hint(&self) -> (Option<uint>, Option<uint>) {
|
fn size_hint(&self) -> (Option<uint>, Option<uint>) {
|
||||||
let exact = Some(((self.end as uint) - (self.ptr as uint)) / size_of::<$elem>());
|
let diff = if $step > 0 {
|
||||||
|
(self.end as uint) - (self.ptr as uint)
|
||||||
|
} else {
|
||||||
|
(self.ptr as uint) - (self.end as uint)
|
||||||
|
};
|
||||||
|
let exact = Some(diff / size_of::<$elem>());
|
||||||
(exact, exact)
|
(exact, exact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3404,6 +3409,16 @@ mod tests {
|
|||||||
assert!(it.next().is_none());
|
assert!(it.next().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_iter_size_hints() {
|
||||||
|
use iterator::*;
|
||||||
|
let mut xs = [1, 2, 5, 10, 11];
|
||||||
|
assert_eq!(xs.iter().size_hint(), (Some(5), Some(5)));
|
||||||
|
assert_eq!(xs.rev_iter().size_hint(), (Some(5), Some(5)));
|
||||||
|
assert_eq!(xs.mut_iter().size_hint(), (Some(5), Some(5)));
|
||||||
|
assert_eq!(xs.mut_rev_iter().size_hint(), (Some(5), Some(5)));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mut_iterator() {
|
fn test_mut_iterator() {
|
||||||
use iterator::*;
|
use iterator::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user