This is not a tutorial blog. It's just a spontaneous testimony after tried Rust for the first time as an amateur😅
It started when I knew Mustafa on Twitter. He's actually still a final-year student from Computer Science Major at Universitas Indonesia, but I like his explanation regarding software engineering things on his Twitter account. We met offline for the first time in November 2023 at Tjikini Lima Cafe when we were working from the cafe together.
He introduced Rust to me through Monad concept explanation when we were discussing it at Tjikini Lima Cafe before. I knew it was a hard topic for me because I usually code frontend things and never go down to the lower level before. This is the beginning for me to learn low-level programming concepts and even try Rust for the first time.
My learning journey is still ongoing until now. There's still a lot of things that I need to understand. But here's my current learning progress on Rust.
The complete installation guide can be seen at Rust Official Docs. If you want to try it, you can follow the installation guide based on your OS.
In my case, I use Windows 11 as my main OS currently. Honestly, it can take time because it requires other Windows tools like Visual Studio 2022, Windows 11 SDK, and the language pack. Somehow, some error occurred in my case, and of course, it forced me to do the reinstallation process several times😅.
I suggest you use WSL if you want to install Rust on your Windows PC/laptop. You can just run the terminal command and just follow the guide (if any).
As a front-end engineer, I usually use NPM or Yarn as the package manager for my web projects/tasks. Rust uses Cargo as its package manager. I can use Cargo to initiate, compile, and run my Rust project.
To create a project, I can run . To compile the project, I can use . And to run the project, it can be executed by running .
For the complete explanation, you can check it here.
I still use VS Code as my main code editor. To help me while coding Rust, I used the rust-analyzer extension to show me the autocomplete recommendation. It also behaves like a code linter to warn the coder if there's syntax that doesn't match.
Now I'll tell you my testimony when trying Rust Syntax. I can't explain all of them in this blog. I only show some highlighted things that I tried before because it's too much and I am still a newbie here. I try my best to tell it in the right way😅.
For the variables declaration, somehow Rust is unique. It also uses keywords like JS to declare variables. But by default, it's not mutable.
For example, like the snippet below. If I run it, it will show an error like below here. Even before I compile it, the rust-analyzer has figured it out early.
I have to put keyword after so it can become mutable.
The full explanation regarding these variables and mutability can be read here.
In my perspective as a frontend engineer who uses Typescript as a daily programming language, Rust also has the data type but is more strict. In other words, I have to be aware of the data type before I build it. Again, even the can detect the mistakes early before I compile it.
Based on the docs, Rust is a statically typed language, which means that it must know the types of all variables at compile time.
In Rust, the data type is actually pretty similar to other programming languages, like integer, float, char, string, array, and tuple. Luckily, by using , it helped me to see what kind of data type of a variable when I declared it. This VS Code extension is so powerful and helpful when coding Rust in VS Code.
You can check the full docs about Rust Data Type here.
For this topic regarding Rust functions, I didn't find any major difficulties when learning it. The thing that I noticed is that when I create a function with the return value, I need to declare the return value data type also. For the parameters, I think it is similar to Typescript behavior when declaring the parameter type.
You can check the full docs here.
Like other programming languages, you can also create some comments in your codes.
Now let's move to the control flow syntax. Let's start with syntax in Rust. For me, the syntax is similar to JS but without when declaring the condition😅.
The unique thing about Rust's is it can be written in one line like this too.
How about syntax? Yes, Rust also has it, but it uses . Full docs about it can be accessed here.
How about looping? There's several approach that can do with Rust when creating the looping code. I can use , , and loop.
Here's an example.
One thing to be aware of, sometimes you have to add keyword when using "for loop". It's related to the Borrow Concept in Rust and I still don't get it fully😅. Full docs here.
There are a lot of things regarding Rust that I need to understand. But so far, those are what I've tried. I even tried it in my Leetcode exercise and maybe it can be proof that low-level programming languages like Rust can be very fast even though I still used the very basic approach.
Again I have to warn you that Rust has quite a hard learning curve. Its compiler sometimes irritating 😅. But somehow it also forces me to code in the right way based on Rust standards.
For now, learning Rust seems "useless" because there are very few job listings that use Rust in Indonesia. But don't hesitate to learn. Don't just learn because of the money, but learn for the sake of your curiosity. I believe learning this hard tech stack can be worth investment for the long term. At least, it will shape your mindset when writing code.
Pssstttt, by the way, I still use VS Code when coding Rust. I am actually very curious about the NeoVim code editor, but it is very confusing for me because I have to get used to remembering the keyboard combinations😅. Maybe I'll use NeoVim (LazyVim) when I code some toy project that does not require fast deliverance so I don't be rushed.