From 709ff5e25d2f019eda2a36659cfbad1c8752de14 Mon Sep 17 00:00:00 2001 From: voidentente Date: Tue, 6 Aug 2024 14:21:03 +0200 Subject: [PATCH] Change let .. else to iterator --- src/ser/mod.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 18ed19f1a..022ae2daa 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -1344,18 +1344,14 @@ impl<'a, W: fmt::Write> ser::SerializeStruct for Compound<'a, W> { let name = iter.next().expect( "is always at least one, because we push one at the beginning of this function", ); - let mut field = config.meta.get_field(name); - while let Some(name) = iter.next() { - let Some(some_field) = field else { break }; - - let Some(fields) = some_field.fields() else { - field = None; - break; - }; - - field = fields.get_field(name); - } + let field = iter + .try_fold(config.meta.get_field(name), |field, name| { + field + .and_then(|field| field.fields()) + .map(|fields| fields.get_field(name)) + }) + .flatten(); if let Some(field) = field { let lines: Vec<_> = field