mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-22 20:52:27 +00:00
use less non-public syn api
This commit is contained in:
parent
5e5e3aaf9d
commit
992d9be195
6 changed files with 10 additions and 14 deletions
|
@ -3,7 +3,6 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||
use quote::{format_ident, quote};
|
||||
use std::cmp::min;
|
||||
use syn::{
|
||||
parse_macro_input,
|
||||
spanned::Spanned,
|
||||
Data,
|
||||
DeriveInput,
|
||||
|
@ -54,7 +53,7 @@ impl ParsedFields
|
|||
fn expand(tokens : TokenStream) -> Result<TokenStream2, Error>
|
||||
{
|
||||
let krate = super::krate();
|
||||
let input = parse_macro_input::parse::<DeriveInput>(tokens)?;
|
||||
let input : DeriveInput = syn::parse(tokens)?;
|
||||
let ident = input.ident;
|
||||
let generics = input.generics;
|
||||
|
||||
|
|
|
@ -151,10 +151,7 @@ impl MethodArgumentType
|
|||
fn quote_ty(&self) -> Option<TokenStream2>
|
||||
{
|
||||
match self {
|
||||
Self::MethodArg(ty) => Some(quote!(#ty)),
|
||||
Self::DatabaseConnection(ty) => Some(quote!(#ty)),
|
||||
Self::AuthStatus(ty) => Some(quote!(#ty)),
|
||||
Self::AuthStatusRef(ty) => Some(quote!(#ty)),
|
||||
Self::MethodArg(ty) | Self::DatabaseConnection(ty) | Self::AuthStatus(ty) | Self::AuthStatusRef(ty) => Some(quote!(#ty)),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
@ -280,7 +277,8 @@ fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result<To
|
|||
let krate = super::krate();
|
||||
|
||||
// parse attributes
|
||||
let mut method_attrs = parse_macro_input::parse::<AttributeArgs>(attrs)?;
|
||||
// TODO this is not public api but syn currently doesn't offer another convenient way to parse AttributeArgs
|
||||
let mut method_attrs : AttributeArgs = parse_macro_input::parse(attrs)?;
|
||||
let resource_path = match method_attrs.remove(0) {
|
||||
NestedMeta::Meta(Meta::Path(path)) => path,
|
||||
p => return Err(Error::new(p.span(), "Expected name of the Resource struct this method belongs to"))
|
||||
|
@ -288,7 +286,7 @@ fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result<To
|
|||
let resource_name = resource_path.segments.last().map(|s| s.ident.to_string())
|
||||
.ok_or_else(|| Error::new(resource_path.span(), "Resource name must not be empty"))?;
|
||||
|
||||
let fun = parse_macro_input::parse::<ItemFn>(item)?;
|
||||
let fun : ItemFn = syn::parse(item)?;
|
||||
let fun_ident = &fun.sig.ident;
|
||||
let fun_vis = &fun.vis;
|
||||
let fun_is_async = fun.sig.asyncness.is_some();
|
||||
|
|
|
@ -90,6 +90,7 @@ fn parse_attributes(input : &[Attribute]) -> Result<Attrs, Error>
|
|||
if attr.path.segments.iter().last().map(|segment| segment.ident.to_string()) == Some("openapi".to_owned())
|
||||
{
|
||||
let tokens = remove_parens(attr.tokens.clone());
|
||||
// TODO this is not public api but syn currently doesn't offer another convenient way to parse AttributeArgs
|
||||
let nested = parse_macro_input::parse::<AttributeArgs>(tokens.into())?;
|
||||
for meta in nested
|
||||
{
|
||||
|
|
|
@ -5,7 +5,6 @@ use quote::quote;
|
|||
use std::iter;
|
||||
use syn::{
|
||||
parenthesized,
|
||||
parse_macro_input,
|
||||
parse::{Parse, ParseStream, Result as SynResult},
|
||||
punctuated::Punctuated,
|
||||
DeriveInput,
|
||||
|
@ -59,7 +58,7 @@ fn impl_openapi_type(ident : &Ident, generics : &Generics) -> TokenStream2
|
|||
fn expand(tokens : TokenStream) -> Result<TokenStream2, Error>
|
||||
{
|
||||
let krate = super::krate();
|
||||
let input = parse_macro_input::parse::<DeriveInput>(tokens)?;
|
||||
let input : DeriveInput = syn::parse(tokens)?;
|
||||
let ident = input.ident;
|
||||
let generics = input.generics;
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||
use quote::quote;
|
||||
use syn::{
|
||||
parenthesized,
|
||||
parse_macro_input,
|
||||
parse::{Parse, ParseStream},
|
||||
punctuated::Punctuated,
|
||||
DeriveInput,
|
||||
|
@ -33,7 +32,7 @@ impl Parse for MethodList
|
|||
fn expand(tokens : TokenStream) -> Result<TokenStream2, Error>
|
||||
{
|
||||
let krate = super::krate();
|
||||
let input = parse_macro_input::parse::<DeriveInput>(tokens)?;
|
||||
let input : DeriveInput = syn::parse(tokens)?;
|
||||
let ident = input.ident;
|
||||
let name = ident.to_string();
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ fn process_variant(variant : Variant) -> Result<ErrorVariant, Error>
|
|||
let status = match variant.attrs.iter()
|
||||
.find(|attr| attr.path.segments.iter().last().map(|segment| segment.ident.to_string()) == Some("status".to_string()))
|
||||
{
|
||||
Some(attr) => Some(parse_macro_input::parse::<Path>(remove_parens(attr.tokens.clone()).into())?),
|
||||
Some(attr) => Some(syn::parse2(remove_parens(attr.tokens.clone()))?),
|
||||
None => None
|
||||
};
|
||||
|
||||
|
@ -85,7 +85,7 @@ fn process_variant(variant : Variant) -> Result<ErrorVariant, Error>
|
|||
let display = match variant.attrs.iter()
|
||||
.find(|attr| attr.path.segments.iter().last().map(|segment| segment.ident.to_string()) == Some("display".to_string()))
|
||||
{
|
||||
Some(attr) => Some(parse_macro_input::parse::<LitStr>(remove_parens(attr.tokens.clone()).into())?),
|
||||
Some(attr) => Some(syn::parse2(remove_parens(attr.tokens.clone()))?),
|
||||
None => None
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue