close
The Wayback Machine - https://web.archive.org/web/20220425153737/https://dev.to/youngmahesh/learning-rust-2j03

DEV Community

Mahesh
Mahesh

Posted on

Learning Rust

Publishing the syntax I learn in rust, so I can keep my thinking as clear as possible.

I will update the article whenever I learn new syntax

Rust playground: https://play.rust-lang.org/

print

println!("{:?}", variable_name) prints integers, strings, vectors

Strings

// split string to form a array of vectors
let numsInStr = "3 4 25 90 233";
let numsInVec: Vec<u32> = num2
      .trim().split(' ')
      .map(|s| s.parse().unwrap())
      .collect();
println!("{:?}", num3);
Enter fullscreen mode Exit fullscreen mode

Array/Vector

let mut vector1 = vec![34,35,60,40,15];  // create vector, mut == vector1 is mutable/modifiable
vector1[3]; // get element at index 3
vector1.push(47);  // push element to vector
vector1.pop(); // remove last element of the vector
vector1.len(); // get length of vector
println!("{:?}", vector1);  // print vector
Enter fullscreen mode Exit fullscreen mode

Discussion (0)