Rust - The journey so far
This article was previously published on len-learns-rust.com. A full index of these articles can be found here.
I’ve now built a generic IdManager
which does everything I want it to do, for now. I’ve bumbled along in a very
non-scientific manner, mostly using the compiler errors to guide me towards
things I’ve then looked up on the web. The code works and is tested, but it’s
now time to go back to the books with a series of questions that this journey
has got me thinking about:
-
I’ve stumbled upon the “Interior Mutability Pattern” and solved it using
std::sync::Mutex
and I hope this means that I can use the code across multiple-threads, but I haven’t tried that yet and theMutex
solution isn’t the only way to approach this, especially if you don’t need multiple threads. -
My “Smart Pointer” could follow the idiomatic Rust Smart Pointer pattern a bit more closely and implement
dref()
rather than an explicitvalue()
method. -
I’d like to understand Generics a bit more, I think I’ve just stumbled across something that works without really understanding everything.
-
I’m keen to remove the test duplication, possibly by using macros…
I think my next step will be to explore threading and try and use this code from multiple threads. Once that’s done I may understand how to use the “Interior Mutability Pattern” in single threaded code and see if Rust prevents me making mistakes if I try and use that code with multiple threads.
When I finally got around to using this code from multiple threads, here, I found that I needed a few small changes.
The code can be found here on GitHub each step on the journey will have one or more separate directories of code.
Of course, there may be a better way; leave comments if you’d like to help me learn.