macros: Simplify Response derive attribute parsing
This commit is contained in:
parent
dff84efb0c
commit
876e8e38aa
@ -12,7 +12,6 @@ mod kw {
|
|||||||
syn::custom_keyword!(query);
|
syn::custom_keyword!(query);
|
||||||
syn::custom_keyword!(query_map);
|
syn::custom_keyword!(query_map);
|
||||||
syn::custom_keyword!(header);
|
syn::custom_keyword!(header);
|
||||||
syn::custom_keyword!(manual_body_serde);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum RequestMeta {
|
pub enum RequestMeta {
|
||||||
@ -76,20 +75,3 @@ impl Parse for ResponseMeta {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum DeriveResponseMeta {
|
|
||||||
ManualBodySerde,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for DeriveResponseMeta {
|
|
||||||
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
|
|
||||||
let lookahead = input.lookahead1();
|
|
||||||
if lookahead.peek(kw::manual_body_serde) {
|
|
||||||
let _: kw::manual_body_serde = input.parse()?;
|
|
||||||
Ok(Self::ManualBodySerde)
|
|
||||||
} else {
|
|
||||||
Err(lookahead.error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -4,17 +4,20 @@ use proc_macro2::TokenStream;
|
|||||||
use quote::{quote, ToTokens};
|
use quote::{quote, ToTokens};
|
||||||
use syn::{
|
use syn::{
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
punctuated::Punctuated,
|
|
||||||
visit::Visit,
|
visit::Visit,
|
||||||
DeriveInput, Field, Generics, Ident, Lifetime, Token, Type,
|
DeriveInput, Field, Generics, Ident, Lifetime, Type,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::attribute::{DeriveResponseMeta, ResponseMeta};
|
use super::attribute::ResponseMeta;
|
||||||
use crate::util::import_ruma_common;
|
use crate::util::import_ruma_common;
|
||||||
|
|
||||||
mod incoming;
|
mod incoming;
|
||||||
mod outgoing;
|
mod outgoing;
|
||||||
|
|
||||||
|
mod kw {
|
||||||
|
syn::custom_keyword!(manual_body_serde);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn expand_derive_response(input: DeriveInput) -> syn::Result<TokenStream> {
|
pub fn expand_derive_response(input: DeriveInput) -> syn::Result<TokenStream> {
|
||||||
let fields = match input.data {
|
let fields = match input.data {
|
||||||
syn::Data::Struct(s) => s.fields,
|
syn::Data::Struct(s) => s.fields,
|
||||||
@ -28,13 +31,9 @@ pub fn expand_derive_response(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let metas =
|
let _ = attr.parse_args::<kw::manual_body_serde>()?;
|
||||||
attr.parse_args_with(Punctuated::<DeriveResponseMeta, Token![,]>::parse_terminated)?;
|
|
||||||
for meta in metas {
|
manual_body_serde = true;
|
||||||
match meta {
|
|
||||||
DeriveResponseMeta::ManualBodySerde => manual_body_serde = true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let response =
|
let response =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user