Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement