Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use crate::List::{Cons, Nil};
- use std::rc::Rc;
- fn main() {
- let the_list = Rc::new(Cons(1, Rc::new(Cons(2, Rc::new(Cons(3, Rc::new(Nil)))))));
- println!("{:?}", the_list);
- let mut list = the_list;
- while let Cons(n, ref l) = *list.clone() {
- println!("{}", n);
- list = Rc::clone(&l);
- }
- }
- #[derive(Debug)]
- enum List<T> {
- Cons(T, Rc<List<T>>),
- Nil,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement