use std::rc::Rc; #[derive(Debug, Clone)] pub struct List { head: Option>>, } #[derive(Debug, Clone)] pub struct Node { data: T, parent: Option>>, } impl List { pub fn new() -> Self { List { head: None } } pub fn push_front(&self, data: T) -> List { List { head: Some(Rc::new(Node { data: data, parent: self.head.clone(), })), } } pub fn get_data(&self) -> Option<&T> { self.head.as_ref().map(|rc_node| &rc_node.data) } }