Просмотр исходного кода

add commented-out, failing example for cons with references.

Lucas Stadler лет назад: 11
Родитель
Сommit
ada418c050
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      rust/pointers.rs

+ 11 - 0
rust/pointers.rs

@ -41,6 +41,14 @@ mod list_with_box {
41 41
        }
42 42
    }
43 43
44
    // pub fn cons_with_ref<A>(x: A, xs: &List<A>) -> List<A> {
45
    //     match *xs {
46
    //         Nil => Cons(x, box Nil),
47
    //         _ => Cons(x, box *xs)
48
    //                       // ^    "cannot move out of dereference of `&`-pointer"
49
    //     }
50
    // }
51
44 52
    pub fn run() {
45 53
        println!("\nlist_with_box:");
46 54
@ -48,6 +56,9 @@ mod list_with_box {
48 56
49 57
        println!("l = {}", l);
50 58
        println!("cons(3, l) = {:?}", cons(3, l));
59
60
        // println!("cons_with_ref(3, &l) = {:?}", cons_with_ref(3, &l));
61
        //                                                        // ^    "use of moved value: `l`"
51 62
    }
52 63
}
53 64