Working by exposing the node type.
This commit is contained in:
		
							parent
							
								
									f2ddf6451c
								
							
						
					
					
						commit
						8dcb1318d6
					
				| @ -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 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander