Store the node in the list.
This commit is contained in:
parent
8dcb1318d6
commit
7976e017fd
@ -10,13 +10,13 @@ use nom::Parser;
|
||||
type Link<'r, T> = Option<&'r Node<'r, T>>;
|
||||
type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
|
||||
|
||||
pub struct Node<'r, T> {
|
||||
struct Node<'r, T> {
|
||||
elem: T,
|
||||
next: Link<'r, T>,
|
||||
}
|
||||
|
||||
pub struct List<'r, T> {
|
||||
head: Link<'r, T>,
|
||||
head: Option<Node<'r, T>>,
|
||||
}
|
||||
|
||||
impl<'r, T> List<'r, T> {
|
||||
@ -24,13 +24,15 @@ impl<'r, T> List<'r, T> {
|
||||
List { head: None }
|
||||
}
|
||||
|
||||
pub fn with_additional_node(&self, element: T) -> Node<'r, T> {
|
||||
pub fn with_additional_node(&'r self, element: T) -> List<'r, T> {
|
||||
let new_node = Node {
|
||||
elem: element,
|
||||
next: self.head,
|
||||
next: self.head.as_ref(),
|
||||
};
|
||||
|
||||
new_node
|
||||
List {
|
||||
head: Some(new_node),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user