Skip to main content

async_trait/
args.rs

1use proc_macro2::Span;
2use syn::parse::{Error, Parse, ParseStream, Result};
3use syn::Token;
4
5#[derive(#[automatically_derived]
impl ::core::marker::Copy for Args { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Args {
    #[inline]
    fn clone(&self) -> Args {
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone)]
6pub struct Args {
7    pub local: bool,
8}
9
10mod kw {
11    #[allow(non_camel_case_types)]
pub struct Send {
    #[allow(dead_code)]
    pub span: ::syn::__private::Span,
}
#[doc(hidden)]
#[allow(dead_code, non_snake_case)]
pub fn Send<__S: ::syn::__private::IntoSpans<::syn::__private::Span>>(span:
        __S) -> Send {
    Send { span: ::syn::__private::IntoSpans::into_spans(span) }
}
const _: () =
    {
        impl ::syn::__private::Default for Send {
            fn default() -> Self {
                Send { span: ::syn::__private::Span::call_site() }
            }
        }
        impl ::syn::__private::CustomToken for Send {
            fn peek(cursor: ::syn::buffer::Cursor) -> ::syn::__private::bool {
                if let ::syn::__private::Some((ident, _rest)) = cursor.ident()
                    {
                    ident == "Send"
                } else { false }
            }
            fn display() -> &'static ::syn::__private::str { "`Send`" }
        }
        impl ::syn::parse::Parse for Send {
            fn parse(input: ::syn::parse::ParseStream)
                -> ::syn::parse::Result<Send> {
                input.step(|cursor|
                        {
                            if let ::syn::__private::Some((ident, rest)) =
                                    cursor.ident() {
                                if ident == "Send" {
                                    return ::syn::__private::Ok((Send { span: ident.span() },
                                                rest));
                                }
                            }
                            ::syn::__private::Err(cursor.error("expected `Send`"))
                        })
            }
        }
        impl ::syn::__private::ToTokens for Send {
            fn to_tokens(&self, tokens: &mut ::syn::__private::TokenStream2) {
                let ident = ::syn::Ident::new("Send", self.span);
                ::syn::__private::TokenStreamExt::append(tokens, ident);
            }
        }
        impl ::syn::__private::Copy for Send {}
        #[allow(clippy :: expl_impl_clone_on_copy)]
        impl ::syn::__private::Clone for Send {
            fn clone(&self) -> Self { *self }
        }
        ;
    };syn::custom_keyword!(Send);
12}
13
14impl Parse for Args {
15    fn parse(input: ParseStream) -> Result<Self> {
16        match try_parse(input) {
17            Ok(args) if input.is_empty() => Ok(args),
18            _ => Err(error()),
19        }
20    }
21}
22
23fn try_parse(input: ParseStream) -> Result<Args> {
24    if input.peek(::syn::token::QuestionToken![?]) {
25        input.parse::<::syn::token::QuestionToken![?]>()?;
26        input.parse::<kw::Send>()?;
27        Ok(Args { local: true })
28    } else {
29        Ok(Args { local: false })
30    }
31}
32
33fn error() -> Error {
34    let msg = "expected #[async_trait] or #[async_trait(?Send)]";
35    Error::new(Span::call_site(), msg)
36}