diff --git a/src/parser/list.rs b/src/parser/list.rs index 2806448d..e685429b 100644 --- a/src/parser/list.rs +++ b/src/parser/list.rs @@ -1,3 +1,4 @@ +use std::fmt::Debug; use std::rc::Rc; #[derive(Debug)] @@ -19,7 +20,8 @@ pub struct Node { parent: Option>>, } -impl List { +// TODO: This Debug is only needed because of the try_unwrap+expect +impl List { pub fn new() -> Self { List { head: None } } @@ -33,6 +35,22 @@ impl List { } } + pub fn pop_front(self) -> (Option, List) { + match self.head { + None => (None, List::new()), + Some(popped_node) => { + let extracted_node = + Rc::try_unwrap(popped_node).expect("TODO I should handle this better"); + ( + Some(extracted_node.data), + List { + head: extracted_node.parent, + }, + ) + } + } + } + pub fn without_front(&self) -> List { List { head: self.head.as_ref().map(|node| node.parent.clone()).flatten(),