mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-18 00:00:15 +02:00
Use map_while (#1720)
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user