Learning Rust at Hacktoberfest in Eight Hours
Tricks for mastering this relatively new technology
This year’s #hacktoberfest became a great opportunity for me to start learning Rust. In this article, I will share a couple of tricks on how to start mastering this relatively new technology.
These are great languages for their purposes, but as with everything, they have some limitations. Specifically, CPU-heavy tasks or things that demand the processing of large amounts of data. There is a movement towards solving those problems, however, it’s not that significant.
That’s where Rust comes in. I heard it is a strong static-type language which inherits the best of C/C++ and provides amazing performance, as well as guaranteeing memory and thread-safe execution.
What an amazing thing it must be! I thought so for months but never had time to test it.
And then I heard about Hacktoberfest from my team members at Redoc.ly who were organizing the event. “That’s it! My chance to switch and learn something new,” I thought. Also, I wanted to give myself the challenge of learning new technology fast.
So, I waited until the local Hacktoberfest event, went there, and started learning.
What Is Hacktoberfest?
Long story short. Hacktoberfest is a great way to contribute to open source and get a cool T-shirt for it.
A bit more info: It is a month-long event by Digital Ocean and DEV. During the event, everybody who creates four or more pull requests for open-source projects hosted on GitHub gets a chance to win a cool T-shirt.
The event gets more popular each year and in 2019, the are more than 500 on-site events where you can join a bunch of other programmers and solve some issues during the day.
To start, I navigated to the official Rust website. The first good sign was that it is really clear and intuitive. Just go to the installation page and copy-paste one single command into your terminal.
And that’s it. You only have a Rust environment manager (which is called
rustup and manages all the toolchains you need), a package manager (
cargo), and a bunch of other useful tools.
When you have the basic installation ready, go to the terminal and type
rustup --version and
cargo --version. That should print versions of the compiler and package manager installed.
For me, I chose to use VS Code which I use for my daily tasks.
Now, we are ready to start hacking.
First of all, let’s create a simple Hello World application to familiarize ourselves with the basic syntax of the Rust.
The official documentation is a great place to start with that. It gives a simple example of a guessing game that I have used to get some understanding of the language.
I won’t even provide it here, as the official tutorial is just awesome and iterates from literally a Hello World to a functional game.
The final result is the following code, which shows a basic example of flow control, I/O, and Rust’s very special approach called ownership. It might be somewhat mind-blowing at first glance, but after some practice, I saw the elegance of this solution.
The guessing game source code is in the official Rust tutorial.
Checking the Toolbox
Sometime after the Hello World I was wondering, how rich is Rust with tooling for testing, linting, and so on?
As I have already mentioned, it has a bunch of editor plugins, but it also turned out that Rust has already developed an ecosystem for most use cases we might need during day-to-day tasks.
Getting Your Hands Dirty
That’s all fine, but it might become boring pretty fast to learn from such synthetical examples. So, I decided to go wild and use Rust for some real projects.
Generally, it’s a brilliant idea for any Hacktoberfest participant to find issues to work on before the event.
In our location, that was a major problem, as lots of people came with no ideas on what to do, so they spent a lot of time crawling over GitHub looking for any viable issues. It’s much easier to spend an hour or two a couple of days before.
I didn’t have any ideas for open-source and neither do we use Rust for main projects in my job (at least, for now). So, what can a programmer do, when they want to write some code but they’re not sure which code?
Browse open source, of course. A couple of days before the event, I opened my browser to find some issues to work with. There are a whole lot of projects written in Rust on GitHub.
Quite a large part of them are popular and have some active issues. I used the Advanced search to find Rust repositories with more than 500 stars.
For myself, I found two projects to contribute to:
- Hyperfine (A console benchmarking tool that I am using day-to-day.)
- Monolith (A tool to download webpages and bundle them into a single .html file.)
After a quick review of the repositories, I found one issue for each of them to work on. Both well-defined, which is extremely useful for a new language and project.
- Option to disable the default output entirely in Hyperfine
- Make it parse CSS as well, replacing url(…) with url(data:…) in Monolith
Issues are self-contained, so I didn’t have to dig through the whole codebase of the project to get those tasks done. A good idea was to contact the repository’s maintainers.
It allows you to:
- Ask if the issue is still relevant (as one of them was quite old).
- Claim that you’ll work on it, so we don’t end up in a weird situation where two or more people are doing the same job.
Authors of both projects responded fast, so I finished my preparations and was waiting for the event. I was not completely sure if I would be able to finish them in time, so I booked the next day to be able to finish contribution on time.
I will not go into details of the implementation as that’s quite project-specific. Here are just a few things I would like to mention about this experience, both regarding the Rust language and my approach in general:
It blew my mind the first time I read about it. Then, I spent some time trying to understand it. Gave up. Tried again. Gave up. Decided to do something useful and eventually got the idea. After that — enjoy it.
Timing is important
It is important for every activity, but the format I participated in was an offline event. So it was twice as crucial as with the online-first approach.
So, plan, maybe even create some reading lists for top five problems you believe you might encounter.
Networking makes a difference
Working on issues was not that hard, so I had plenty of time to spend on networking.
And, even though there weren’t all that many participants, it was a great opportunity to borrow some experience from different ecosystems with which I rarely interact.
Outcome and Thoughts
I didn’t learn Rust in eight hours. However, it was an amazing start after which I:
- Started to contribute to open-source software.
- Found tons of interesting projects with Rust.
- Began diving into the long-forgotten (for me) domain of the low to mid-level programming languages.
- Gathered with cool people.
Such activities might not be necessary for your development as an engineer, but, I believe it will help with that.
Additional Resources and Tutorials
If you have heard about Rust (or other tools that you have never tried out), I strongly encourage you to give it a try!
Life’s short and we should use each opportunity to learn something new and potentially useful. Especially if the learning process will bring some value, not only for us but for the whole community as well.
If you, like myself, tried or are going to try Rust, you might end up liking it, looking for more information and tutorials.
In this part I will list the ones which I find the most useful:
- The book is an overview of the language from the first principles up to quite complicated approaches.
- Rustlings guides you through installing the Rust toolchain and teaches you the basics of the language.
- Rust by example is an alternative to reading pages of docs, Rust by example shows off a bunch of code and keeps the talking to a minimum. It also includes exercises!
- Rust crash course is a set of articles that guide you from the very beginning to quite detailed language details. However, the style is reader-friendly to follow.
Also, there are two books which tend to be highly appreciated on the web, as a good starting point. I did not read them yet, but will mention them here to show you the full picture:
- The Rust Programming Language. This is a guide to Rust, written by two members of the Rust core team, with feedback and contributions from 42 members of the community.
- Programming Rust: Fast, Safe Systems Development. Written by two experienced systems programmers, this book explains how Rust manages to bridge the gap between performance and safety, and how you can take advantage of it.
Finally, there are some useful questions and answers which you can find on Stack Overflow.
That’s the end of this piece, but I hope it’s the start of your experience with Rust. Keep hacking!