Basic Lines of Code in Rust
- Types
isize,i32,i64,f64
- Variables
let mut n: i64 = 42;let mut n = 42;let n = 42;let mut words = Vec::<String>::new();let mut mat = Matrix::<f64>::new();let mut contactInfoForID = HashMap::<String, ContactInfo>::new();
- Functions
fn multiply(a: i64, b: i64) -> i64 { a * b }fn print(a: &ContactInfo) { ...; }fn concat(a: &str, b: &str) -> String { return ...; }
- Loops
for i in 1..=10 { ...; }for i in 0..words.len() { ...; }for i in [5, 7, 11, 13].iter() { ...; }for word in words.iter() { ...; }
Note
In Rust42is ani32, not ani64.