Going through rustlings for the first time
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 31 lines 936 B view raw
1use std::mem; 2 3#[rustfmt::skip] 4#[allow(unused_variables, unused_assignments)] 5fn main() { 6 let my_option: Option<()> = None; 7 // `unwrap` of an `Option` after checking if it is `None` will panic. 8 // Use `if-let` instead. 9 if let Some(value) = my_option { 10 println!("{value:?}"); 11 } 12 13 // A comma was missing. 14 let my_arr = &[ 15 -1, -2, -3, 16 -4, -5, -6, 17 ]; 18 println!("My array! Here it is: {:?}", my_arr); 19 20 let mut my_empty_vec = vec![1, 2, 3, 4, 5]; 21 // `resize` mutates a vector instead of returning a new one. 22 // `resize(0, …)` clears a vector, so it is better to use `clear`. 23 my_empty_vec.clear(); 24 println!("This Vec is empty, see? {my_empty_vec:?}"); 25 26 let mut value_a = 45; 27 let mut value_b = 66; 28 // Use `mem::swap` to correctly swap two values. 29 mem::swap(&mut value_a, &mut value_b); 30 println!("value a: {}; value b: {}", value_a, value_b); 31}