From 197aad3c945a06bb239d31c78dcb312d624bcdff Mon Sep 17 00:00:00 2001 From: Dominic Date: Sun, 20 Oct 2019 15:44:20 +0200 Subject: [PATCH] clippy --- gotham_restful_derive/src/from_body.rs | 44 ++++++++++---------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/gotham_restful_derive/src/from_body.rs b/gotham_restful_derive/src/from_body.rs index 79af118..633998f 100644 --- a/gotham_restful_derive/src/from_body.rs +++ b/gotham_restful_derive/src/from_body.rs @@ -16,37 +16,27 @@ pub fn expand_from_body(tokens : TokenStream) -> TokenStream let (were, body) = match input.fields { Fields::Named(named) => { let fields = named.named; - if fields.len() == 0 // basically unit - { - (quote!(), quote!(Self{})) - } - else if fields.len() == 1 - { - let field = fields.first().unwrap(); - let field_ident = field.ident.as_ref().unwrap(); - let field_ty = &field.ty; - (quote!(where #field_ty : for<'a> From<&'a [u8]>), quote!(Self { #field_ident: body.into() })) - } - else - { - panic!("FromBody can only be derived for structs with at most one field") + match fields.len() { + 0 => (quote!(), quote!(Self{})), + 1 => { + let field = fields.first().unwrap(); + let field_ident = field.ident.as_ref().unwrap(); + let field_ty = &field.ty; + (quote!(where #field_ty : for<'a> From<&'a [u8]>), quote!(Self { #field_ident: body.into() })) + }, + _ => panic!("FromBody can only be derived for structs with at most one field") } }, Fields::Unnamed(unnamed) => { let fields = unnamed.unnamed; - if fields.len() == 0 // basically unit - { - (quote!(), quote!(Self{})) - } - else if fields.len() == 1 - { - let field = fields.first().unwrap(); - let field_ty = &field.ty; - (quote!(where #field_ty : for<'a> From<&'a [u8]>), quote!(Self(body.into()))) - } - else - { - panic!("FromBody can only be derived for structs with at most one field") + match fields.len() { + 0 => (quote!(), quote!(Self{})), + 1 => { + let field = fields.first().unwrap(); + let field_ty = &field.ty; + (quote!(where #field_ty : for<'a> From<&'a [u8]>), quote!(Self(body.into()))) + }, + _ => panic!("FromBody can only be derived for structs with at most one field") } }, Fields::Unit => (quote!(), quote!(Self{}))