Guest User

Untitled

a guest
Jun 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. pub fn pop(&mut self) -> Option<i32> {
  2. match mem::replace(&mut self.head, Link::Empty) {
  3. Link::Empty => None,
  4. Link::More(boxed_node) => {
  5. let node = *boxed_node;
  6. self.head = node.next;
  7. Some(node.elem)
  8. }
  9. }
  10. }
  11.  
  12. pub fn pop(&mut self) -> Option<i32> {
  13. match mem::replace(&mut self.head, Link::Empty) {
  14. Link::Empty => None,
  15. Link::More(node) => {
  16. self.head = node.next;
  17. Some(node.elem)
  18. }
  19. }
  20. }
  21.  
  22. struct Node {
  23. elem: i32,
  24. next: Link,
  25. }
  26.  
  27. enum Link {
  28. Empty,
  29. More(Box<Node>),
  30. }
Add Comment
Please, Sign In to add comment