Skip to content

Instantly share code, notes, and snippets.

@Costava
Created May 6, 2022 01:43
Show Gist options
  • Save Costava/55480e8face7d19a6a9d1a8b1ab286b5 to your computer and use it in GitHub Desktop.
Save Costava/55480e8face7d19a6a9d1a8b1ab286b5 to your computer and use it in GitHub Desktop.
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