Lately, I’ve been noticing this programming language mentioned here and there. Not very often, but enough to catch my attention. I read that it’s a language without a garbage collector but with a design that ensures memory safety. This seemed quite interesting, so I’d been waiting to find some time to explore it further.
One day, I got up early, had some free time, and decided to dive into it. I turned on my laptop and started learning Rust, experimenting with its features. I installed rustup
on my Windows system, which is the tool used to set up Rust and cargo
, Rust’s package manager.
Learning a new programming language is always intriguing. I was eager to pick it up quickly, so I decided to write a simple prime number generator. I headed over to Rust’s documentation and their playground. There, I learned about some basic concepts like struct
, traits
, impl
, and other aspects of Rust’s syntax. I also learned about the fn main()
function, which is the entry point of a program, just like in C
or C++
. Since I already knew these languages, Rust felt quite intuitive to me.
I managed to write a prime number generator using the Sieve of Eratosthenes algorithm. I ran it using cargo run main.rs
. Boom! I encountered several compilation errors complaining about borrowing or cloning some objects.
After some investigation and with the help of AI, I was able to fix the code and run it successfully. It only took about 200ms to generate primes up to 1,000,000, compared to Python, which took approximately 1.2 seconds.
Next, I tried optimizing the prime generator further using bit operations. I implemented a bitwise sieve to push the upper limit of prime number generation to 100,000,000.
Here’s the code if you’re curious:
I already started devloping a desktop app using Rust and Tauri. And plan to write more about it in the future.
So far, so good! I love this language and will continue exploring Rust to delve deeper into its core.