]> git.lizzy.rs Git - rust.git/blobdiff - src/test/run-pass/static-impl.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / static-impl.rs
index d0dacc2ff7a9d225a4cec29e68091ac35937b21e..74c0663971ec5e773e6c9e91b26fc34e0186c8fd 100644 (file)
@@ -26,14 +26,14 @@ impl plus for String { fn plus(&self) -> int { 200 } }
 
 trait uint_utils {
     fn str(&self) -> String;
-    fn multi(&self, f: |uint|);
+    fn multi<F>(&self, f: F) where F: FnMut(uint);
 }
 
 impl uint_utils for uint {
     fn str(&self) -> String {
         self.to_string()
     }
-    fn multi(&self, f: |uint|) {
+    fn multi<F>(&self, mut f: F) where F: FnMut(uint) {
         let mut c = 0u;
         while c < *self { f(c); c += 1u; }
     }
@@ -41,14 +41,14 @@ fn multi(&self, f: |uint|) {
 
 trait vec_utils<T> {
     fn length_(&self, ) -> uint;
-    fn iter_(&self, f: |&T|);
-    fn map_<U>(&self, f: |&T| -> U) -> Vec<U> ;
+    fn iter_<F>(&self, f: F) where F: FnMut(&T);
+    fn map_<U, F>(&self, f: F) -> Vec<U> where F: FnMut(&T) -> U;
 }
 
 impl<T> vec_utils<T> for Vec<T> {
     fn length_(&self) -> uint { self.len() }
-    fn iter_(&self, f: |&T|) { for x in self.iter() { f(x); } }
-    fn map_<U>(&self, f: |&T| -> U) -> Vec<U> {
+    fn iter_<F>(&self, mut f: F) where F: FnMut(&T) { for x in self.iter() { f(x); } }
+    fn map_<U, F>(&self, mut f: F) -> Vec<U> where F: FnMut(&T) -> U {
         let mut r = Vec::new();
         for elt in self.iter() {
             r.push(f(elt));
@@ -63,9 +63,9 @@ pub fn main() {
 
     assert_eq!((vec!(1i)).length_().str(), "1".to_string());
     let vect = vec!(3i, 4).map_(|a| *a + 4);
-    assert_eq!(*vect.get(0), 7);
-    let vect = (vec!(3i, 4)).map_::<uint>(|a| *a as uint + 4u);
-    assert_eq!(*vect.get(0), 7u);
+    assert_eq!(vect[0], 7);
+    let vect = (vec!(3i, 4)).map_::<uint, _>(|a| *a as uint + 4u);
+    assert_eq!(vect[0], 7u);
     let mut x = 0u;
     10u.multi(|_n| x += 2u );
     assert_eq!(x, 20u);