nimbuscode.dev/technologies/rust
C:\> cat TECHNOLOGIES/RUST.md
Loading Rust documentation...

Rust

Programming Language

1. Introduction

Rust is a multi-paradigm, general-purpose programming language designed for performance and safety, especially safe concurrency. Rust is syntactically similar to C++, but provides memory safety without using garbage collection. It achieves memory safety through a novel ownership system with a compiler that enforces rules at compile time.

Rust was originally designed by Graydon Hoare at Mozilla Research and is now governed by the Rust Foundation. It consistently ranks as the "most loved programming language" in the Stack Overflow Developer Survey since 2016.

2. Syntax Examples

Hello World and Basic Types
// Hello World program
fn main() {
    println!("Hello, world!");
    
    // Basic variable declaration
    let x: i32 = 42;        // immutable by default
    let mut y: i32 = 10;    // mutable
    y = 20;                 // OK because y is mutable
    
    // Type inference
    let z = 3.14;           // f64 inferred
    
    // Tuples
    let tuple: (i32, f64, bool) = (42, 3.14, true);
    println!("{:?}", tuple);
    
    // Arrays
    let array: [i32; 5] = [1, 2, 3, 4, 5];
    println!("Array: {:?}", array);
}
Ownership, Borrowing, and References
fn main() {
    // Ownership example
    let s1 = String::from("hello");
    let s2 = s1;  // s1 is moved to s2, s1 is no longer valid
    
    // Uncomment to see error:
    // println!("{}", s1);  // ❌ Error: value borrowed after move
    println!("{}", s2);  // This works
    
    // Borrowing with references
    let s3 = String::from("hello world");
    
    // Immutable borrow
    let len = calculate_length(&s3);
    println!("The length of '{}' is {}.", s3, len);
    
    // Mutable borrow
    let mut s4 = String::from("hello");
    append_world(&mut s4);
    println!("{}", s4); // "hello world"
}

fn calculate_length(s: &String) -> usize {
    s.len()
    // s goes out of scope, but it's just a reference,
    // so the value it refers to is not dropped
}

fn append_world(s: &mut String) {
    s.push_str(" world");
}
Structs, Enums, and Pattern Matching
// Struct
struct Person {
    name: String,
    age: u32,
}

// Method implementation for Person
impl Person {
    fn new(name: String, age: u32) -> Person {
        Person { name, age }
    }
    
    fn greet(&self) {
        println!("Hi, I'm {} and I'm {} years old", self.name, self.age);
    }
}

// Enum
enum Result {
    Ok(T),
    Err(E),
}

fn main() {
    // Using structs
    let person = Person::new(String::from("Alice"), 30);
    person.greet();
    
    // Pattern matching with Option
    let some_number = Some(5);
    let absent_number: Option<i32> = None;
    
    match some_number {
        Some(n) => println!("The number is {}", n),
        None => println!("No number found"),
    }
    
    // If let shorthand
    if let Some(n) = some_number {
        println!("Found number: {}", n);
    }
}

3. Main Uses

Rust excels in many domains:

  • Systems programming
  • WebAssembly (Wasm) applications
  • Network services and distributed systems
  • Embedded devices
  • Command-line tools
  • Game development
  • Operating systems and kernels
  • Performance-critical applications

4. Pros and Cons

Advantages

  • Memory safety without garbage collection
  • Zero-cost abstractions
  • Thread safety and concurrent programming support
  • Excellent compiler error messages
  • Robust type system with pattern matching
  • Performance comparable to C and C++
  • Growing ecosystem with Cargo package manager

Limitations

  • Steep learning curve, especially ownership concepts
  • Longer compilation times compared to some languages
  • Smaller ecosystem compared to more established languages
  • Fighting with the borrow checker (especially for beginners)
  • Not ideal for rapid prototyping
  • Can be verbose for simple tasks
  • Project maturity issues in some domains

5. Rust Evolution

Rust has evolved through several phases:

  • 2010 - First introduced by Mozilla Research
  • 2012 - Rust 0.1 released
  • 2015 - Rust 1.0 stable released
  • 2018 - Rust 2018 Edition
  • 2021 - Rust 2021 Edition, Rust Foundation formed
  • 2023-2025 - Ongoing development with 6-week release cycle

Rust follows a 6-week release cycle for incremental updates and introduces major "editions" every three years that can include more significant syntax and feature changes while maintaining backward compatibility.

6. Learning Resources

Here are some excellent resources for learning Rust:

7. Related Technologies

Technologies and languages that relate to Rust:

C:\> cd ../