Skip to content

Instantly share code, notes, and snippets.

@kenyipp
Last active December 17, 2022 18:50
Show Gist options
  • Save kenyipp/7e130f421dfc65d85f41262b48863ac9 to your computer and use it in GitHub Desktop.
Save kenyipp/7e130f421dfc65d85f41262b48863ac9 to your computer and use it in GitHub Desktop.
Sample script to demonstrate how to use vector in rust
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