mirror of
https://github.com/tokio-rs/axum.git
synced 2025-02-17 02:34:28 +01:00
Use map_while
(#1720)
This commit is contained in:
parent
6ff6b36293
commit
47be78e0b3
1 changed files with 6 additions and 9 deletions
|
@ -137,15 +137,12 @@ where
|
|||
{
|
||||
let a = a.map(Some).chain(std::iter::repeat_with(|| None));
|
||||
let b = b.map(Some).chain(std::iter::repeat_with(|| None));
|
||||
a.zip(b)
|
||||
// use `map_while` when its stable in our MSRV (1.57)
|
||||
.take_while(|(a, b)| a.is_some() || b.is_some())
|
||||
.filter_map(|(a, b)| match (a, b) {
|
||||
(Some(a), Some(b)) => Some(Item::Both(a, b)),
|
||||
(Some(a), None) => Some(Item::First(a)),
|
||||
(None, Some(b)) => Some(Item::Second(b)),
|
||||
(None, None) => unreachable!("take_while removes these"),
|
||||
})
|
||||
a.zip(b).map_while(|(a, b)| match (a, b) {
|
||||
(Some(a), Some(b)) => Some(Item::Both(a, b)),
|
||||
(Some(a), None) => Some(Item::First(a)),
|
||||
(None, Some(b)) => Some(Item::Second(b)),
|
||||
(None, None) => None,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Add table
Reference in a new issue