I'm still learning Rust. Now I tried to create some sort of restricted LinkedList using lifetimes.
To accomplish what I wanted to do I had to split up my insert method:
pub fn insert1<'lifetime_node>(&self, node: &'lifetime_node mut ListNode<'lifetime_list, T>) -> ()
{
node.next = self.next;
}
pub fn insert2(&mut self, node: &'lifetime_list ListNode<'lifetime_list, T>) -> ()
{
self.next = Option::<&Self>::Some(node);
}
Is there a way to put both into one function while keeping the mutable reference only for as long as the function call but the immutable reference for longer?