Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.40 KB | None | 0 0
  1. enum List {
  2.     // Cons: Tuple struct that wraps an element and a pointer to the next node
  3.     Cons(u32, Box<List>),
  4.     // Nil: A node that signifies the end of the linked list
  5.     Nil,
  6. }
  7.  
  8. fn car(l : &List) -> u32 {
  9.     match *l {
  10.         Nil => 420,
  11.         Cons(n, _) => n
  12.     }
  13. }
  14.  
  15. fn cdr(l: &List) -> &List {
  16.     match *l {
  17.         Nil => &Nil,
  18.         Cons(_,ref tail) => tail
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement