SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top