start

fn main() {
    println!("0x1RIS");
}

Output:

0x1RIS

cargo

cargo new hello
cargo run
cargo test

cargo is build tool, package manager, and test runner One command, one manifest, no build script archaeology

Edition

The edition field in Cargo.toml selects language rules Edition 2024 is the current one Older editions stay supported, so code from three years ago still compiles

The first error

fn main() {
    let s1 = String::from("hello");
    let s2 = s1;
    println!("{s1}, world!");
}

That does not compile s1 was moved into s2 The compiler points at the line where the move happened and the line where the use happened

That error is the feature In C it would compile and free the same memory twice In Rust it stops before it becomes a bug

Why this is different

No garbage collector No manual free Ownership rules checked at compile time Runtime speed, compile time pain, and the pain is worth it

Next

Variables and types in 02 variables and types

Posted