Implementing a Linked List

I'm learning rust and after my first program[1] I continue with some simple data structures. So I decided to implement a simple linked list[2].
Naturally, I since I need the last element for other functions, I thought about creating a function that returns the last element in the list[3]. Which in my head should work, but the compiler says I'm wrong :slight_smile:
Apparently, I just can't return self because I borrow it for the match. Is it generally a bad idea to want to change the data I'm matching from? This would happen with Tree structures too, so I'm a bit baffled.

[1] Requesting a Code Review
[2] Rust Playground
[3] Rust Playground

It's a known shortcoming of the current borrow checker.

Here's one workaround.


Incidentally:

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.