SHARE
TWEET

Untitled

a guest Sep 20th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use crate::List::{Cons, Nil};
  2. use std::rc::Rc;
  3.  
  4. fn main() {
  5.     let the_list = Rc::new(Cons(1, Rc::new(Cons(2, Rc::new(Cons(3, Rc::new(Nil)))))));
  6.     println!("{:?}", the_list);
  7.  
  8.     let mut list = the_list;
  9.     while let Cons(n, ref l) = *list.clone() {
  10.         println!("{}", n);
  11.         list = Rc::clone(&l);
  12.     }
  13. }
  14.  
  15. #[derive(Debug)]
  16. enum List<T> {
  17.     Cons(T, Rc<List<T>>),
  18.     Nil,
  19. }
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