contentintech
Languages

Rust

Cargo, ownership and Result-based error handling.

Updated Official documentation ↗

Cargo

cargo new helloCreate a binary project
cargo checkType-check without producing a final executable
cargo testRun unit and integration tests
cargo fmtFormat the project

Values and ownership

let count = 3;Bind an immutable value
let mut count = 3;Allow reassignment or mutation
let name = String::from("Ada");Own a heap-allocated string
let borrowed = &name;Borrow without moving ownership

Collections and results

let values = vec![1, 2, 3];Construct a vector
values.iter().map(|n| n * 2).collect::<Vec<_>>()Transform borrowed elements
Some(42)Represent an optional value
let text = std::fs::read_to_string(path)?;Propagate an error from a function returning a compatible Result

Section navigation