From 3e0c125b12341d388b4a12e13099a7c2f3dfec98 Mon Sep 17 00:00:00 2001 From: Hadrien G Date: Sat, 12 Oct 2019 18:19:24 +0200 Subject: [PATCH] Simplify extent() using fold --- src/lib.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7bb7b87..8aa6053 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,9 +17,10 @@ fn derive_abomonation(mut s: synstructure::Structure) -> proc_macro2::TokenStrea ::abomonation::Entomb::entomb(#bi, _write)?; }); - let extent = s.each(|bi| quote! { - sum += ::abomonation::Entomb::extent(#bi); - }); + let extent = s.fold( + quote!(0), + |acc, bi| quote!(#acc + ::abomonation::Entomb::extent(#bi)) + ); s.bind_with(|_| synstructure::BindStyle::RefMut); @@ -37,11 +38,8 @@ fn derive_abomonation(mut s: synstructure::Structure) -> proc_macro2::TokenStrea Ok(()) } - #[allow(unused_mut)] fn extent(&self) -> usize { - let mut sum = 0; match *self { #extent } - sum } }