From 47be78e0b341bf82888a404d7a62d572be47a592 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Tue, 24 Jan 2023 12:49:36 +0100 Subject: [PATCH] Use `map_while` (#1720) --- axum/src/routing/strip_prefix.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/axum/src/routing/strip_prefix.rs b/axum/src/routing/strip_prefix.rs index 521b774e..7daef140 100644 --- a/axum/src/routing/strip_prefix.rs +++ b/axum/src/routing/strip_prefix.rs @@ -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)]