The best approach to learning Rust

I have started by reading the Rust book, but at some point the mere reading was not enough - without the practice the information fades away... So I took a real-world project (a C#-based network management and provisioning system which I had previously moved from Windows to Linux using mono), and started to rewrite the pieces of it - it had conveniently several standalone processes which were doing well-defined tasks and are small enough - reachability checker, syslog server, configuration updater, etc.. I have about a month to get as much of it running as possible before it will need to do the "real world" job - but I have the C# components to fall back on, which were already battle-tested.

This proved great as a learning approach: Starting at first with diesel for basic database interaction and simple web-based queries, then ssh2, git2, etc, and having the need to make these interact together exposes a good way to get a feel for the borrow checker behaviour - even though I have read the stack overflow question, the details of "how to make it work" remained unclear until after maybe a day or so of hitting the wall I got the "Ah-ha!" moment, and could progress further.

Of course, also heavily relying on examples in the docs, too, and refreshing by random re-reading of the book, but now I reinforce the learning by needing the language features as solutions to "real" problems that I face (sometimes these problems are of my own making, like this unnecessary (ab)use of macros. In the end I came to a much simpler and elegant solution, but got a bit of handle on the use of macros.

After a few of the "how does it work and why I can not get it compiled?" occurrences I also have started to grab the source of the crates, and peek there - rather than merely looking at the type signatures.

So, my (beginner) opinion - pick a non-constrained project in some other language, preferably more backend/low-level (I can not say about frontend as I did not move to rewriting the frontend portion yet), for which you are comfortable with knowing the use case and which can be modularised into small independent pieces, and rewrite parts of it in Rust.

So - good luck and enjoy it. It's not very easy sometimes but certainly the joy once you "make it work" very rewarding!

p.s. also: I want to take a chance to thank a lot all the kind folks with whom I have interacted so far, both here and on stackoverflow! I do my homework, but sometimes it takes a second pair of eyes to notice the obvious :slight_smile:

3 Likes