Skip to content

Instantly share code, notes, and snippets.

@panicbit
Created June 20, 2018 13:15
Show Gist options
  • Save panicbit/730c49946eef34e5f93187fee779d369 to your computer and use it in GitHub Desktop.
Save panicbit/730c49946eef34e5f93187fee779d369 to your computer and use it in GitHub Desktop.
let mut head = Node::new(vec[0].clone());
let mut current_head: &mut Node<T> = &mut head;
for &next in &vec[1..] {
let moved_head = current_head; // Takes the mutable reference away from current_head
moved_head.right = Some(Box::new(Node::new(next.clone())));
current_head = moved_head.right.as_mut().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment