Skip to main content

Command Palette

Search for a command to run...

Getting Started with Rust: A Modern Systems Programming Language

Published
4 min readView as Markdown
Getting Started with Rust: A Modern Systems Programming Language

Getting Started with Rust: A Modern Systems Programming Language

Rust is a powerful, modern systems programming language designed for performance, safety, and concurrency. It has gained immense popularity among developers for its ability to prevent common programming errors like null pointer dereferences and data races while maintaining high performance.

If you're looking to learn Rust and leverage your programming skills to make money online, platforms like MillionFormula can help you monetize your expertise—completely free, with no credit or debit cards required.

Why Learn Rust?

Rust offers several advantages over traditional systems programming languages like C and C++:

  • Memory Safety: Rust's ownership model eliminates data races and null pointer exceptions at compile time.

  • Performance: Rust provides zero-cost abstractions, meaning high-level code compiles to efficient machine code.

  • Concurrency: Fearless concurrency allows writing safe parallel code without headaches.

  • Growing Ecosystem: With a robust package manager (Cargo) and a supportive community, Rust is ideal for systems programming, web assembly, and more.

Installing Rust

To get started, install Rust using rustup, the official Rust toolchain installer:

bash

Copy

Download

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

Follow the on-screen instructions, then verify the installation:

bash

Copy

Download

rustc --version

Your First Rust Program

Let’s write a simple "Hello, World!" program in Rust.

  1. Create a new project using Cargo:

bash

Copy

Download

cargo new hello_world
cd hello_world
  1. Open src/main.rs and write:

rust

Copy

Download

fn main() {
    println!("Hello, World!");
}
  1. Run the program:

bash

Copy

Download

cargo run

You should see Hello, World! printed in your terminal.

Understanding Rust Basics

Variables and Mutability

Rust variables are immutable by default. To make them mutable, use the mut keyword:

rust

Copy

Download

let x = 5;       // Immutable
let mut y = 10;   // Mutable
y = 15;           // Allowed
// x = 7;         // Error: Cannot assign to immutable variable

Data Types

Rust is statically typed, meaning types are checked at compile time. Common types include:

  • Integers: i32, u64, etc.

  • Floats: f32, f64

  • Booleans: bool

  • Characters: char (Unicode scalar values)

Example:

rust

Copy

Download

let num: i32 = 42;
let pi: f64 = 3.14159;
let is_rust_cool: bool = true;
let emoji: char = '🚀';

Functions

Functions are defined using fn. Here’s a simple function that adds two numbers:

rust

Copy

Download

fn add(a: i32, b: i32) -> i32 {
    a + b  // No semicolon implies return
}
fn main() {
let sum = add(5, 7);
println!("Sum: {}", sum);  // Output: Sum: 12
}

Ownership and Borrowing

Rust’s ownership model ensures memory safety without a garbage collector.

  • Ownership Rules:

    • Each value has a single owner.

    • When the owner goes out of scope, the value is dropped.

  • Borrowing:

    • References (&) allow borrowing without taking ownership.

Example:

rust

Copy

Download

fn main() {
    let s = String::from("hello");
    print_string(&s);  // Borrowing
    println!("Original string: {}", s);  // Still accessible
}
fn print_string(s: &String) {
println!("{}", s);
}

Building a Simple Project

Let’s create a CLI tool that greets the user.

  1. Create a new project:

bash

Copy

Download

cargo new greet
cd greet
  1. Modify src/main.rs:

rust

Copy

Download

use std::io;
fn main() {
println!("What's your name?");
let mut name = String::new();
io::stdin()
.read_line(&mut name)
.expect("Failed to read input");
println!("Hello, {}!", name.trim());
}
  1. Run it:

bash

Copy

Download

cargo run

Where to Go Next?

Monetizing Your Rust Skills

If you're looking to make money online with your Rust (or any programming) skills, check out MillionFormula, a free platform where you can earn without needing credit or debit cards.

Conclusion

Rust is an excellent language for systems programming, offering safety, speed, and modern tooling. By mastering Rust, you open doors to high-performance applications, embedded systems, and even blockchain development. Start coding today and explore opportunities to monetize your skills!

Happy coding! 🚀

More from this blog

MillionFormula

67 posts