about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-07-11 21:10:59 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-07-12 01:53:50 -0400
commit2b96408600c33b81c3c41f661764aa8d80cf3c9d (patch)
treee720a03eb6d2c44dd65da00a2d07b901f1a150c9 /src
parent07183ea6e719e18f5d6b09afbe519c9f940c4705 (diff)
downloadrust-2b96408600c33b81c3c41f661764aa8d80cf3c9d.tar.gz
rust-2b96408600c33b81c3c41f661764aa8d80cf3c9d.zip
extend the iterator tutorial
documents conversion, size hints and double-ended iterators and adds
more of the traits to the prelude
Diffstat (limited to 'src')
-rw-r--r--src/libextra/bitv.rs8
-rw-r--r--src/libstd/prelude.rs5
-rw-r--r--src/libstd/vec.rs2
-rw-r--r--src/test/run-pass/rcvr-borrowed-to-slice.rs14
4 files changed, 14 insertions, 15 deletions
diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs
index dc65ef36b67..f1637ae96a2 100644
--- a/src/libextra/bitv.rs
+++ b/src/libextra/bitv.rs
@@ -104,7 +104,7 @@ impl SmallBitv {
     }
 
     #[inline]
-    pub fn invert(&mut self) { self.bits = !self.bits; }
+    pub fn negate(&mut self) { self.bits = !self.bits; }
 }
 
 struct BigBitv {
@@ -160,7 +160,7 @@ impl BigBitv {
     }
 
     #[inline]
-    pub fn invert(&mut self) { for self.each_storage |w| { *w = !*w } }
+    pub fn negate(&mut self) { for self.each_storage |w| { *w = !*w } }
 
     #[inline]
     pub fn union(&mut self, b: &BigBitv, nbits: uint) -> bool {
@@ -366,9 +366,9 @@ impl Bitv {
 
     /// Invert all bits
     #[inline]
-    pub fn invert(&mut self) {
+    pub fn negate(&mut self) {
       match self.rep {
-        Small(ref mut b) => b.invert(),
+        Small(ref mut b) => b.negate(),
         Big(ref mut s) => for s.each_storage() |w| { *w = !*w } }
     }
 
diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs
index db534cca971..ea49144b771 100644
--- a/src/libstd/prelude.rs
+++ b/src/libstd/prelude.rs
@@ -47,8 +47,9 @@ pub use cmp::{Eq, ApproxEq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Great
 pub use char::Char;
 pub use container::{Container, Mutable, Map, Set};
 pub use hash::Hash;
-pub use iter::{Times};
-pub use iterator::{Iterator, IteratorUtil, OrdIterator};
+pub use iter::Times;
+pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator, DoubleEndedIteratorUtil};
+pub use iterator::OrdIterator;
 pub use num::{Num, NumCast};
 pub use num::{Orderable, Signed, Unsigned, Round};
 pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic};
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 89c4b39c429..4ab93da8c09 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -760,6 +760,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
                         lifetime: cast::transmute(p)}
         }
     }
+
     #[inline]
     fn rev_iter(self) -> VecRevIterator<'self, T> {
         self.iter().invert()
@@ -2211,7 +2212,6 @@ impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
     }
 }
 
-
 #[cfg(test)]
 mod tests {
     use option::{None, Option, Some};
diff --git a/src/test/run-pass/rcvr-borrowed-to-slice.rs b/src/test/run-pass/rcvr-borrowed-to-slice.rs
index b62475ded54..3df60762dea 100644
--- a/src/test/run-pass/rcvr-borrowed-to-slice.rs
+++ b/src/test/run-pass/rcvr-borrowed-to-slice.rs
@@ -11,19 +11,17 @@
 use std::vec;
 
 trait sum {
-    fn sum(self) -> int;
+    fn sum_(self) -> int;
 }
 
 // Note: impl on a slice
 impl<'self> sum for &'self [int] {
-    fn sum(self) -> int {
-        let mut sum = 0;
-        for self.iter().advance |e| { sum += *e; }
-        return sum;
+    fn sum_(self) -> int {
+        self.iter().fold(0, |a, &b| a + b)
     }
 }
 
-fn call_sum(x: &[int]) -> int { x.sum() }
+fn call_sum(x: &[int]) -> int { x.sum_() }
 
 pub fn main() {
     let x = ~[1, 2, 3];
@@ -32,12 +30,12 @@ pub fn main() {
     assert_eq!(y, 6);
 
     let mut x = ~[1, 2, 3];
-    let y = x.sum();
+    let y = x.sum_();
     debug!("y==%d", y);
     assert_eq!(y, 6);
 
     let x = ~[1, 2, 3];
-    let y = x.sum();
+    let y = x.sum_();
     debug!("y==%d", y);
     assert_eq!(y, 6);
 }