mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-19 22:44:38 +00:00
clippy
This commit is contained in:
parent
5282dbbe6c
commit
197aad3c94
1 changed files with 17 additions and 27 deletions
|
@ -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
|
||||
{
|
||||
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() }))
|
||||
}
|
||||
else
|
||||
{
|
||||
panic!("FromBody can only be derived for structs with at most one field")
|
||||
},
|
||||
_ => 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
|
||||
{
|
||||
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())))
|
||||
}
|
||||
else
|
||||
{
|
||||
panic!("FromBody can only be derived for structs with at most one field")
|
||||
},
|
||||
_ => panic!("FromBody can only be derived for structs with at most one field")
|
||||
}
|
||||
},
|
||||
Fields::Unit => (quote!(), quote!(Self{}))
|
||||
|
|
Loading…
Add table
Reference in a new issue