Rust programming language: use cases and examples

Technology 2 min 20 Mar 2023
Cover image for Rust programming language: use cases and examples
Where Rust shines (systems, Wasm, games, networking, concurrency) plus short code samples for beginners.

Rust, originally from Mozilla, is a modern language built around performance, memory safety, and concurrency. It targets low-level systems work and stands out with ownership rules that catch data races early. Here is where it shows up, plus a few small examples.

Where Rust is a good fit

  • Systems programming: OS pieces, embedded work, and drivers benefit from speed without the usual memory foot-guns.
  • WebAssembly: Rust compiles cleanly to Wasm for fast, safer browser-side code.
  • Games: Useful when you need performance and safer memory behavior in engine or tooling code.
  • Networking: Strong for services that must stay fast and careful under load.
  • Parallel and concurrent work: The type system and ownership model help structure concurrent programs.

Rust examples

Below are tiny samples of everyday Rust.

a. Hello world

fn main() {
    println!("Hello, world!");
}

b. Variables and constants

fn main() {
    let x = 10; // immutable
    let mut y = 20; // mutable
    const Z: i32 = 30;

    y = 25;
    println!("x: {}, y: {}, Z: {}", x, y, Z);
}

c. Control flow

fn main() {
    let x = 5;

    if x > 10 {
        println!("x is greater than 10.");
    } else {
        println!("x is less than or equal to 10.");
    }

    for i in 1..6 {
        println!("i: {}", i);
    }

    let mut counter = 1;
    while counter <= 5 {
        println!("counter: {}", counter);
        counter += 1;
    }

    let number = 3;
    match number {
        1 => println!("One"),
        2 => println!("Two"),
        3 => println!("Three"),
        _ => println!("Other"),
    }
}

d. Functions

fn main() {
    let x = 5;
    let y = 10;
    let result = add(x, y);
    println!("Sum: {}", result);
}

fn add(a: i32, b: i32) -> i32 {
    a + b
}

e. Structs and enums

struct Point {
    x: f64,
    y: f64,
}

enum Direction {
    Up,
    Down,
    Left,
    Right,
}

fn main() {
    let p = Point { x: 3.0, y: 4.0 };
    println!("Point: ({}, {})", p.x, p.y);

    let direction = Direction::Up;
    match direction {
        Direction::Up => println!("Up"),
        Direction::Down => println!("Down"),
        Direction::Left => println!("Left"),
        Direction::Right => println!("Right"),
    }
}

Wrap-up

Rust rewards teams that care about performance and safety at the same time. Learn the ownership model, work through small examples, and it becomes a sharp tool for systems, Wasm, games, networking, and concurrent services.

Oğuzhan Koçaklı

I have worked professionally in marketing, gaming and blockchain since 2015. I have helped create and carry out marketing strategies for many major brands. These days I work on mobile games and blockchain integration for games. AI has been my hobby for many years.

All posts

Leave a Reply

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