mirror of
https://github.com/theryangeary/choose
synced 2024-11-23 11:23:11 +00:00
Validate vector indeces
This commit is contained in:
parent
4b6d44e121
commit
e7197092b5
1 changed files with 5 additions and 1 deletions
|
@ -19,7 +19,11 @@ impl Choice {
|
||||||
let words: Vec<&str> = line.split_whitespace().collect();
|
let words: Vec<&str> = line.split_whitespace().collect();
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Choice::Field(i) => print!("{} ", words[*i as usize]),
|
Choice::Field(i) => {
|
||||||
|
if *i < words.len().try_into().unwrap() {
|
||||||
|
print!("{} ", words[*i as usize]);
|
||||||
|
}
|
||||||
|
},
|
||||||
Choice::FieldRange(r) => match r {
|
Choice::FieldRange(r) => match r {
|
||||||
(None, None) => print!("{}", words.into_iter().collect::<String>()),
|
(None, None) => print!("{}", words.into_iter().collect::<String>()),
|
||||||
(Some(start), None) => print!(
|
(Some(start), None) => print!(
|
||||||
|
|
Loading…
Reference in a new issue