Skip to content

Instantly share code, notes, and snippets.

@pzol
Last active January 2, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pzol/8348507 to your computer and use it in GitHub Desktop.
Save pzol/8348507 to your computer and use it in GitHub Desktop.
list_test.rs:35:16: 35:20 error: use of moved value: `list`
enum List<T> {
Cons(T, ~List<T>),
Empty
}
fn length<T>(xs: &List<T>) -> uint {
match *xs {
Empty => 0,
Cons(_, ref rest) => 1 + length(*rest)
}
}
fn prepend<T>(xs: List<T>, value: T) -> List<T> {
Cons(value, ~xs)
}
fn head<T>(xs: &List<T>) -> Option<T> {
match *xs {
Cons(ref value, _) => Some(*value),
_ => None
}
}
#[test]
fn test_length() {
let mut list: List<int> = Empty::<int>;
list = prepend(list, 1);
list = prepend(list, 2);
let list_len = length(&list);
assert_eq!(list_len, 2);
let h = head(&list);
assert_eq!(h, Some(2));
}
/Users/pzol/Dropbox/src/rust/one/src/list_test.rs:22:32: 22:38 error: cannot move out of dereference of & pointer
/Users/pzol/Dropbox/src/rust/one/src/list_test.rs:22 Cons(ref value, _) => Some(*value),
^~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment