Skip to content

Commit

Permalink
Simplify extent() using fold
Browse files Browse the repository at this point in the history
  • Loading branch information
HadrienG2 committed Oct 12, 2019
1 parent efe7144 commit 3e0c125
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
}
}

Expand Down

0 comments on commit 3e0c125

Please sign in to comment.