↓ Skip to main content

Learning Rust, Part 1

·64 words·1 min·
lrweck
Author
lrweck
Developer writing about tech, observations, and experiments.
rust-series - This article is part of a series.
Part 1: This Article

Week one with Rust. The borrow checker and I are not friends yet, but we are negotiating.

fn main() {
    let s = String::from("hello");
    let n = &s;
    let m = &s;
    println!("{n} {m}");
    println!("{}", s);
}

Key insight so far: immutable borrows can coexist, mutable borrows are exclusive. Once that sank in, half the compiler errors started making sense. More in part two.

rust-series - This article is part of a series.
Part 1: This Article

Related