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 {
|
let (were, body) = match input.fields {
|
||||||
Fields::Named(named) => {
|
Fields::Named(named) => {
|
||||||
let fields = named.named;
|
let fields = named.named;
|
||||||
if fields.len() == 0 // basically unit
|
match fields.len() {
|
||||||
{
|
0 => (quote!(), quote!(Self{})),
|
||||||
(quote!(), quote!(Self{}))
|
1 => {
|
||||||
}
|
let field = fields.first().unwrap();
|
||||||
else if fields.len() == 1
|
let field_ident = field.ident.as_ref().unwrap();
|
||||||
{
|
let field_ty = &field.ty;
|
||||||
let field = fields.first().unwrap();
|
(quote!(where #field_ty : for<'a> From<&'a [u8]>), quote!(Self { #field_ident: body.into() }))
|
||||||
let field_ident = field.ident.as_ref().unwrap();
|
},
|
||||||
let field_ty = &field.ty;
|
_ => panic!("FromBody can only be derived for structs with at most one field")
|
||||||
(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")
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Fields::Unnamed(unnamed) => {
|
Fields::Unnamed(unnamed) => {
|
||||||
let fields = unnamed.unnamed;
|
let fields = unnamed.unnamed;
|
||||||
if fields.len() == 0 // basically unit
|
match fields.len() {
|
||||||
{
|
0 => (quote!(), quote!(Self{})),
|
||||||
(quote!(), quote!(Self{}))
|
1 => {
|
||||||
}
|
let field = fields.first().unwrap();
|
||||||
else if fields.len() == 1
|
let field_ty = &field.ty;
|
||||||
{
|
(quote!(where #field_ty : for<'a> From<&'a [u8]>), quote!(Self(body.into())))
|
||||||
let field = fields.first().unwrap();
|
},
|
||||||
let field_ty = &field.ty;
|
_ => panic!("FromBody can only be derived for structs with at most one field")
|
||||||
(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")
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Fields::Unit => (quote!(), quote!(Self{}))
|
Fields::Unit => (quote!(), quote!(Self{}))
|
||||||
|
|
Loading…
Add table
Reference in a new issue