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
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