]> git.lizzy.rs Git - rust.git/blobdiff - src/test/run-pass/overload-index-operator.rs
Replace all ~"" with "".to_owned()
[rust.git] / src / test / run-pass / overload-index-operator.rs
index b995e9c9ed2e3c114cf33ab6792e2f9498abfd19..b72c4f92ea3e796cf73641c725b712759a800f77 100644 (file)
@@ -14,9 +14,9 @@
 use std::ops::Index;
 
 struct AssociationList<K,V> {
-    pairs: ~[AssociationPair<K,V>]
-}
+    pairs: Vec<AssociationPair<K,V>> }
 
+#[deriving(Clone)]
 struct AssociationPair<K,V> {
     key: K,
     value: V
@@ -28,24 +28,24 @@ fn push(&mut self, key: K, value: V) {
     }
 }
 
-impl<K:Eq,V:Copy> Index<K,V> for AssociationList<K,V> {
+impl<K:Eq,V:Clone> Index<K,V> for AssociationList<K,V> {
     fn index(&self, index: &K) -> V {
-        for self.pairs.iter().advance |pair| {
+        for pair in self.pairs.iter() {
             if pair.key == *index {
-                return copy pair.value;
+                return pair.value.clone();
             }
         }
-        fail!("No value found for key: %?", index);
+        fail!("No value found for key: {:?}", index);
     }
 }
 
 pub fn main() {
-    let foo = ~"foo";
-    let bar = ~"bar";
+    let foo = "foo".to_owned();
+    let bar = "bar".to_owned();
 
-    let mut list = AssociationList {pairs: ~[]};
-    list.push(copy foo, 22);
-    list.push(copy bar, 44);
+    let mut list = AssociationList {pairs: Vec::new()};
+    list.push(foo.clone(), 22);
+    list.push(bar.clone(), 44);
 
     assert!(list[foo] == 22)
     assert!(list[bar] == 44)