Skip to content

Commit

Permalink
Fix Sequence for Option<Empty>
Browse files Browse the repository at this point in the history
  • Loading branch information
stephaneyfx committed Jan 15, 2024
1 parent 929b68a commit 410abab
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion enum-iterator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl<T: Sequence> Sequence for Option<T> {

fn next(&self) -> Option<Self> {
match self {
None => Some(T::first()),
None => T::first().map(Some),
Some(x) => x.next().map(Some),
}
}
Expand Down Expand Up @@ -934,6 +934,21 @@ mod tests {
assert!(all::<Option<bool>>().eq([None, Some(false), Some(true)]));
}

#[test]
fn all_bool_option_items_are_yielded_in_reverse() {
assert!(reverse_all::<Option<bool>>().eq([Some(true), Some(false), None]));
}

#[test]
fn all_infallible_option_items_are_yielded() {
assert!(all::<Option<Infallible>>().eq([None]));
}

#[test]
fn all_infallible_option_items_are_yielded_in_reverse() {
assert!(reverse_all::<Option<Infallible>>().eq([None]));
}

#[test]
fn cardinality_equals_item_count_for_ordering() {
cardinality_equals_item_count::<Ordering>();
Expand Down

0 comments on commit 410abab

Please sign in to comment.