Skip to content

Commit

Permalink
fix(variadics): fix HomogenousVariadic get and get_mut only ret…
Browse files Browse the repository at this point in the history
…urning `None` (#1325)
  • Loading branch information
MingweiSamuel authored Jun 28, 2024
1 parent 8eb8aa1 commit c70114d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions variadics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ where
if i == 0 {
Some(item)
} else {
rest.get(i)
rest.get(i - 1)
}
}
fn get_mut(&mut self, i: usize) -> Option<&mut T> {
let (item, rest) = self;
if i == 0 {
Some(item)
} else {
rest.get_mut(i)
rest.get_mut(i - 1)
}
}

Expand Down Expand Up @@ -470,4 +470,13 @@ mod test {
);
assert!(ref_iter.next().is_none());
}

#[test]
fn test_homogenous_get() {
let mut var = var_expr!(0, 1, 2, 3, 4);
for i in 0..5 {
assert_eq!(Some(i), var.get(i).copied());
assert_eq!(Some(i), var.get_mut(i).copied());
}
}
}

0 comments on commit c70114d

Please sign in to comment.