Last active
December 17, 2022 18:50
-
-
Save kenyipp/7e130f421dfc65d85f41262b48863ac9 to your computer and use it in GitHub Desktop.
Sample script to demonstrate how to use vector in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
// let a = [1, 2, 3]; | |
// let mut v1: Vec<i32> = Vec::new(); | |
// let v2 = vec![1, 2, 3]; | |
let mut v = vec![1, 2, 3, 4, 5]; | |
match v.get(2) { | |
Some(third) => println!("The third element is {}", third), | |
None => println!("There is no third element"), | |
} | |
println!("{:#?}", v.get(10)); | |
for i in &mut v { | |
// Dereference operator | |
*i += 50; | |
} | |
for i in &v { | |
println!("{}", i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment