Rust Introduction
Compile a small program before adding abstractions.
How it works
Rust is a compiled language with a type system that checks many ownership and borrowing rules before a program runs. Those checks help with memory safety, but do not prove that business rules, input data or results are correct. Our original examples concern a fictional community seed-tray exchange. Start with a known calculation and a testable output instead of treating compilation as the end of review.
Run the code
Reviewed with Rust 1.97.0, edition 2024, using the standard library only. Save the complete download as lesson-name.rs in a separate learning folder, compile with rustc --edition=2024 lesson-name.rs and run the resulting program (lesson-name.exe on Windows). Use the actual lesson filename. The final project includes complete Cargo package files; run cargo test --offline and cargo run --offline from that separate package folder. There is no Rust browser runner; PHP, Apache and MySQL are not needed.
This complete example was executed in the stated local review environment.
Example
fn main() {
let trays = 4_u32;
assert_eq!(trays * 3, 12);
println!("Seed exchange: {} packets", trays * 3);
}
Expected result
Seed exchange: 12 packets
The explicit unsigned integer type makes the value’s representation visible. assert_eq checks a known result before println formats it. Save the complete download as introduction.rs, compile it with rustc --edition=2024 introduction.rs, then run the produced program. No web server or database is involved.
Primary technical reference: Rust documentation.