Working by exposing the node type.

This commit is contained in:
Tom Alexander 2022-11-24 15:06:07 -05:00
parent f2ddf6451c
commit 8dcb1318d6
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 11 additions and 11 deletions

View File

@ -7,30 +7,30 @@ use nom::error::VerboseError;
use nom::IResult;
use nom::Parser;
type Link<T> = Option<Box<Node<T>>>;
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>>;
struct Node<T> {
pub struct Node<'r, T> {
elem: T,
next: Link<T>,
next: Link<'r, T>,
}
pub struct List<T> {
head: Link<T>,
pub struct List<'r, T> {
head: Link<'r, T>,
}
impl<T> List<T> {
impl<'r, T> List<'r, T> {
pub fn new() -> Self {
List { head: None }
}
pub fn push(&mut self, element: T) {
let new_node = Box::new(Node {
pub fn with_additional_node(&self, element: T) -> Node<'r, T> {
let new_node = Node {
elem: element,
next: self.head.take(),
});
next: self.head,
};
self.head = Some(new_node);
new_node
}
}