Rust Introduction & Setup
Estimated reading: 4 minutes 34 views

🦀 Rust – Get Started: Beginner’s Guide to Building with Rust

🧲 Introduction – Why Get Started with Rust Today?

Rust is taking the programming world by storm for all the right reasons: memory safety, speed, and developer-friendly tooling. If you’ve just completed your first “Hello World” program, you’re now ready to take the next step—understanding how to build, run, and grow real Rust applications.

🎯 In this guide, you’ll learn:

  • How to structure and run Rust projects with cargo
  • Create and manage source files
  • Understand compilation output
  • Explore next-step concepts like variables and data types

🛠️ Create a Rust Project with Cargo

cargo is Rust’s official build system and package manager. It’s your go-to tool for compiling code, downloading libraries, running tests, and managing dependencies.

✅ Step-by-Step: Create a New Project

cargo new rust_get_started
cd rust_get_started

This command creates a folder structure like:

rust_get_started/
├── Cargo.toml       # Project config file
└── src/
    └── main.rs      # Starting point of your application

📜 Write Rust Code in main.rs

Inside src/main.rs, write:

fn main() {
    let name = "Rustacean";
    println!("Welcome to Rust, {}!", name);
}

🔍 Breakdown:

  • let name = "Rustacean"; ➜ Declares an immutable variable
  • println!() ➜ Outputs formatted text to console

▶️ Build and Run the Project

cargo run

📤 Output:

   Compiling rust_get_started v0.1.0
    Finished dev [unoptimized + debuginfo] target(s)
     Running `target/debug/rust_get_started`
Welcome to Rust, Rustacean!

🧱 Compiled Output

Rust builds your app and stores the binary in:

target/debug/rust_get_started

Use cargo build if you only want to compile without running.


📁 Project File Overview

File/FolderDescription
Cargo.tomlMetadata, version, dependencies
src/main.rsYour main program source
target/Build artifacts and compiled binaries
.gitignoreGenerated to ignore target/ and other files

📦 Cargo.toml is where you’ll add external crates (libraries) as your project grows.


🔄 Add Logic: Working with Variables

Let’s build a basic program that uses variables and arithmetic:

fn main() {
    let length = 10;
    let width = 5;
    let area = length * width;

    println!("Area of rectangle is: {}", area);
}

📤 Output:

Area of rectangle is: 50

This demonstrates:

  • Immutable bindings (let)
  • Integer types and basic math
  • The println! macro with placeholders

🌐 Explore Rust Playground (Optional)

Want to try code without local setup?

🔗 https://play.rust-lang.org

This browser-based editor supports Rust syntax highlighting, output preview, and sharing code snippets.


🔄 Next Steps: Topics to Learn After Setup

TopicDescription
Variables & ConstantsMutability, shadowing, and typing
Data TypesIntegers, floats, strings, booleans, tuples
Control Flowif, else, match, loops
FunctionsReusable blocks of logic with parameters
OwnershipThe heart of Rust’s safety model

📌 Summary – Recap & Next Steps

You’ve now created your first full Rust project using cargo, learned how to write and run Rust code, and explored how Rust compiles source files to executables. You’re set to start learning Rust’s deeper concepts like ownership and borrowing.

🔍 Key Takeaways:

  • Use cargo new and cargo run for efficient Rust development
  • Code lives in src/main.rs; binaries go in target/
  • Rust’s syntax is clean and encourages safe programming
  • You’re ready for Rust’s data types, variables, and control flow

⚙️ Up next: Dive into Rust variables and constants to learn how values are stored and managed.


❓FAQs


Do I need an IDE to work with Rust?
✅ No, a basic text editor (VS Code, Sublime, Vim) plus the terminal is enough. Extensions like rust-analyzer enhance your coding experience.


What is cargo in Rust?
cargo is the Rust package manager and build system. It handles project setup, compilation, dependency management, and more.


Where is the compiled binary stored?
✅ In the target/debug/ directory after running cargo build or cargo run.


How do I test small snippets without creating a project?
✅ Use the Rust Playground or save code to a file and compile with rustc file.rs.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

Rust – Get Started

Or Copy Link

CONTENTS
Scroll to Top