DEV Community

Cover image for Getting Started with Rust: Why, How, and What's Next (Part 1)
Ayas Hussein
Ayas Hussein

Posted on

Getting Started with Rust: Why, How, and What's Next (Part 1)

If you've been following tech trends, you've heard the buzz about Rust. It's been voted the "most loved programming language" on Stack Overflow for several years running. But what exactly is it? Is it worth the learning curve? And how do you actually get started?

In this tutorial, we'll cover the fundamentals of Rust, why you should consider adding it to your toolkit, how to install it, and how its ecosystem works.

Stay tuned for Part 2, where we'll use these basics to build a high-performance REST API.

Why Use Rust?

Rust isn't just another scripting language. It sits in a unique spot between low-level control (like C++) and high-level ergonomics (like Python). Here are the three main reasons developers are switching:

1. Memory Safety Without Garbage Collection

In languages like Java or Python, a "Garbage Collector" cleans up memory for you, which can cause unpredictable pauses. In C or C++, you manage memory manually, which often leads to crashes and security vulnerabilities.

Rust introduces a unique system called Ownership. It checks memory safety at compile time. If your code tries to access memory it shouldn't, the compiler refuses to build the program. This means no segfaults, no data races, and no garbage collector.

2. Blazing Performance

Because Rust doesn't have a runtime or garbage collector, it is incredibly fast. It is comparable to C++ in performance, making it perfect for systems programming, game engines, high-frequency trading, and web backends.

3. Modern Tooling

Rust comes with a built-in package manager and build tool called Cargo. It handles dependencies, builds, testing, and documentation out of the box. No more configuring webpack or pip environments manually.


Installation: Getting Up and Running

Installing Rust is straightforward thanks to a tool called rustup. It manages your Rust version and tools.

Step 1: Install Rustup

Open your terminal (Command Prompt, PowerShell, or Bash) and run the following command:

macOS / Linux:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Enter fullscreen mode Exit fullscreen mode

Windows:
Download and run rustup-init.exe from the official website.

During installation, press Enter to confirm the default settings. This will install the compiler (rustc), the package manager (cargo), and standard libraries.

Step 2: Verify Installation

Close and reopen your terminal, then type:

rustc --version
cargo --version
Enter fullscreen mode Exit fullscreen mode

You should see version numbers printed out. If so, you're ready!

Step 3: Editor Setup

Rust code can be complex, so you need an editor that understands it.

  1. Download VS Code (recommended).
  2. Install the rust-analyzer extension.
    • Note: Do not install the old "Rust" extension. rust-analyzer is the official and most powerful tool.

Understanding the Ecosystem (Not "Frameworks")

A common question coming from languages like JavaScript (Node.js) or Python (Django) is: "What is the Rust framework?"

The answer is: There isn't just one.

Rust relies on an ecosystem of libraries called Crates. You pick and choose the crates you need to build your application. This gives you flexibility but requires you to make choices.

For Web Development and APIs (which we will cover in the next post), these are the top contenders:

Framework Best For Description
Axum Ergonomics & Type Safety Currently the most recommended. Built on Tokio, very modular.
Actix-web Performance Known for being incredibly fast, though slightly steeper learning curve.
Rocket Ease of Use Very expressive and easy to read, but historically had slower release cycles.

For our upcoming REST API tutorial, we will be using Axum, as it represents the modern standard for Rust web development.


The Basics: Your First Project

Let's create a project to understand how Rust code is structured.

1. Create a Project

Navigate to your coding folder and run:

cargo new hello_rust
cd hello_rust
Enter fullscreen mode Exit fullscreen mode

2. Explore the Structure

Open the folder in VS Code. You'll see:

  • Cargo.toml: The configuration file (like package.json). This is where you add dependencies.
  • src/main.rs: The entry point of your application.

3. Write Some Code

Open src/main.rs. You'll see this:

fn main() {
    println!("Hello, world!");
}
Enter fullscreen mode Exit fullscreen mode

Let's make it slightly more interesting to see Rust's basics in action:

fn main() {
    // Variables are immutable by default
    let name = "Developer"; 

    // Use 'mut' to make a variable mutable
    let mut message = String::from("Welcome to Rust"); 

    println!("Hello, {}! {}", name, message);

    // Update the mutable variable
    message = String::from("Let's build something fast");
    println!("{}", message);
}
Enter fullscreen mode Exit fullscreen mode

4. Run It

Back in your terminal, run:

cargo run
Enter fullscreen mode Exit fullscreen mode

Output:

Hello, Developer! Welcome to Rust
Let's build something fast
Enter fullscreen mode Exit fullscreen mode

What's Next?

You now have Rust installed, you understand why it's powerful, and you've written your first program. But the real power of Rust shines when you build networked applications. In the next , I am going to create some endpoints using Rocket.

Top comments (0)