RUST Experience From Scratch - 01

rust dev.to

Hello dev community πŸ‘‹

First of all, let me introduce myself!

I am a final-year Computer Science undergraduate, a freelance full-stack developer, and DevOps engineer. I have hands-on experience with C++, Java, and Python. Recently, I started exploring Rust, and I quickly realized just how magical of a language it is.


Why Rust?

From my perspective, Rust provides unmatched memory safety guarantees without needing a garbage collector. It strikes a sweet spot low-level enough for system performance, yet high-level enough for ergonomic developer experience.

Once your code compiles, the chance of runtime failure drops drastically. A few things that made me fall in love with Rust:

  • Intelligent Compiler: Its helpful error messages read almost like human advice.
  • Blazing Fast Execution: Built-in performance optimizations ensure high-speed operations.
  • Modern Tooling: cargo makes dependency management and building effortless.

While Rust is notorious for its steep learning curve (thanks to the borrow checker!), its world-class documentation, tooling, and supportive community make learning it completely worth the effort!


Getting Started with Rust

1. Installation

  • Linux / macOS: Run this command in your terminal:
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Enter fullscreen mode Exit fullscreen mode

2. Creating Your First Project

When you install Rust, you also get Cargo Rust’s official build system and package manager. Cargo handles building your code, downloading libraries, and managing dependencies.

To create a new project, run:

cargo new hello-world
Enter fullscreen mode Exit fullscreen mode

This creates a new folder named hello-world with all the necessary boilerplate.

Navigate inside the project and open src/main.rs.


Hello World with Rust πŸ‘‹πŸŒ

Inside src/main.rs, you'll see:

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

Booyaah!! πŸ₯³ You’re looking at your first Rust program!

Quick Note: Notice the ! at the end of println!? That means it’s a Rust Macro, not a standard function call. Macros are a form of metaprogramming (code that writes code) and are extremely powerful in Rust. We’ll dive deeper into macros in a future post!


Running the Project

To compile and execute your app, run Cargo's run command in your project root:

cargo run
Enter fullscreen mode Exit fullscreen mode

You’ll see output similar to this:

hello-world git:(master) βœ— cargo run
   Compiling hello-world v0.1.0 (/path/to/hello-world)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.86s
     Running `target/debug/hello-world`
Hello, World!
Enter fullscreen mode Exit fullscreen mode

What's Next?

This is just the start of my Rust journey! In the upcoming post, I'll cover variables.

Drop a comment below if you're also learning Rust or planning to start! Happy coding! πŸ¦€

Source: dev.to

arrow_back Back to Tutorials