Move the list to its own file.
This commit is contained in:
parent
170ddec9a9
commit
89148a623c
29
src/parser/list.rs
Normal file
29
src/parser/list.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct List<T> {
|
||||
head: Option<Rc<Node<T>>>,
|
||||
}
|
||||
|
||||
pub struct Node<T> {
|
||||
data: T,
|
||||
parent: Option<Rc<Node<T>>>,
|
||||
}
|
||||
|
||||
impl<T> List<T> {
|
||||
pub fn new() -> Self {
|
||||
List { head: None }
|
||||
}
|
||||
|
||||
pub fn push_front(&self, data: T) -> List<T> {
|
||||
List {
|
||||
head: Some(Rc::new(Node {
|
||||
data: data,
|
||||
parent: self.head.clone(),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_data(&self) -> &T {
|
||||
&self.data
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
mod list;
|
||||
mod new_context;
|
||||
mod nom_context;
|
||||
mod parser_with_context;
|
||||
|
@ -1,8 +1 @@
|
||||
pub struct List<T> {
|
||||
head: Option<Rc<Node<T>>>,
|
||||
}
|
||||
|
||||
pub struct Node<T> {
|
||||
data: T,
|
||||
parent: Option<Rc<Node<T>>>,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user