Implementing simple linked-list @ exercism

This is a part of the optional track, so it is not very likely to receive much attention there, but I need some help with this exercise. My code now sort of work, and passes the unit tests, but I don’t really understand what I wrote. The solution is very much a hack and I am sure it could be done better.

My code and the unit test is posted @ my own gist here:

It works, but not great, and I don’t know why it works (putting in all the code i see in previous tutorials to make it work), and I don’t even know where to start asking. Perhaps start from rev()? is there a way to not clone twice (once in rev, another in rev_recurse)?

If you want to get a deeper understanding of this kind of thing, I’d recommend reading the first few chapters of ‘Learning Rust With Entirely Too Many Linked Lists’.

Don’t be discouraged if you’re finding writing these kinds of data structures harder than you would in other languages - Rust’s ownership rules make it a lot more difficult to get right than you might expect. There’s a reason there’s a whole online book written about it :stuck_out_tongue:

yea, some of the codes are copied from there lol @.@

1 Like

You may want to check out slotmap, which makes implementing things like this trivial.

Thanks, looks neat, but would rather do this without external crate so I understand the language better