1extern crate proc_macro;
2
3pub(crate) mod kind;
4#[doc(inline)]
5pub use kind::Kind;
6
7#[derive(Debug, Clone)]
8pub enum Error {
9 Unsupported(kind::Kind, proc_macro2::Span),
10 Syn(syn::Error),
11}
12
13impl From<syn::Error> for Error {
14 fn from(error: syn::Error) -> Self {
15 Self::Syn(error)
16 }
17}
18
19pub trait DeriveInput {
20 fn input(self) -> syn::DeriveInput;
21}
22
23impl DeriveInput for syn::DeriveInput {
24 fn input(self) -> syn::DeriveInput {
25 self
26 }
27}
28
29impl DeriveInput for proc_macro::TokenStream {
30 fn input(self) -> syn::DeriveInput {
31 syn::parse(self).unwrap()
32 }
33}
34
35impl DeriveInput for proc_macro2::TokenStream {
36 fn input(self) -> syn::DeriveInput {
37 syn::parse(self.into()).unwrap()
38 }
39}
40
41pub trait FromDeriveInput: Sized {
42 type Error;
43 fn parse<T: DeriveInput>(input: T) -> Result<Self, Self::Error>;
44}
45
46pub fn parse<D: DeriveInput, T: FromDeriveInput>(input: D) -> Result<T, T::Error> {
47 T::parse(input)
48}