First of all, thank you for adding Rust supposrt in the first place. I know that it must have taken some work. That said, the problems that involve linked lists and rust are extremely unidomatic and hard to work around.
I think the main problem is that rust alreaady includes a very idomatic and fast type for handling lists in the form of vectors. If the linked list problems were translated as vectors in rust it would make most of the problems trivial. While this is an issue, no rust programmer would ever, under any circumstances, use the ListNode interface given for the problems.
Rust uses implicit memory mamangement based on "ownership" and "borrowing". When you insert a ListNode into a ListNode.next you don't just record it there, you move its only valid handle in the entire program to there.
You can read through the list easily enough using references, but my god, adding or changing. You have to take sole ownershop of the next node out of the list, as well as any other nodes that need to be moved, and then reconnect them in a direction from the tail towards the head. This is one programmers work around for deleting an element and reconnecting the list.
https://leetcode.com/problems/remove-nth-node-from-end-of-list/discuss/220627/Rust-0-ms-solution
for _ in 0..(idx) { p = p.unwrap().next.as_mut(); }
let next = p.as_mut().unwrap().next.as_mut().unwrap().next.take();
p.as_mut().unwrap().next = next; In idomatic rust, with p as a vector, this would be written:
p.remove(idx);I understand why this perfectly fine solution is considered far to trivial for the question at hand, but the ListNode work around seems a bit heavy handed, and imo makes rust look like far less efficient a language than it is.