Rust Commands
Memory-safe systems language and its compiler, rustc.All Rust pages
- rust convert string to int with parse::<i32>()Convert a string to an integer in Rust with s.parse::<i32>(), which returns a Result. Error kinds, trim() for user input, other bases, defaults, type inference.
- rust read a file line by line (BufReader::lines and read_to_string)Read a file line by line in Rust with BufReader::new(File::open(path)?).lines(), or all at once with fs::read_to_string. Line endings, errors and UTF-8 issues.
- rustc --explain E0382: show the explanation of a Rust error coderustc --explain E0382 prints the full explanation of a Rust compiler error code, with an erroneous example and fixes. It works offline; cargo --explain too.
- rustc main.rs: compile and run a single Rust file without CargoCompile and run one Rust file without Cargo: rustc --edition 2024 main.rs, then ./main. Optimize with -O, name the output, read errors, and when to use Cargo.