Created
May 6, 2022 01:43
-
-
Save Costava/55480e8face7d19a6a9d1a8b1ab286b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
if std::env::args().count() != 2 { | |
panic!("Pass exactly 1 argument: an index"); | |
} | |
let index = match std::env::args().nth(1).unwrap().parse::<usize>() { | |
Ok(i) => i, | |
Err(_) => panic!("Pass a non-negative integer"), | |
}; | |
let array: [i32; 4] = [0, 1, 2, 3]; | |
println!("index: {}", index); | |
println!("value: {}", array[index]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment