initial commit

This commit is contained in:
Sampras Lopes
2022-11-16 20:37:50 +05:30
commit 430dcd1967
320 changed files with 64760 additions and 0 deletions

View File

@ -0,0 +1,33 @@
use proc_macro2::Span;
use quote::ToTokens;
use syn::{parse::Parse, punctuated::Punctuated, spanned::Spanned, Attribute, Token};
pub fn non_enum_error() -> syn::Error {
syn::Error::new(Span::call_site(), "This macro only supports enums.")
}
pub(super) fn occurrence_error<T: ToTokens>(
first_keyword: T,
second_keyword: T,
attr: &str,
) -> syn::Error {
let mut error = syn::Error::new_spanned(
second_keyword,
format!("Found multiple occurrences of error({})", attr),
);
error.combine(syn::Error::new_spanned(first_keyword, "first one here"));
error
}
pub(super) fn get_metadata_inner<'a, T: Parse + Spanned>(
ident: &str,
attrs: impl IntoIterator<Item = &'a Attribute>,
) -> syn::Result<Vec<T>> {
attrs
.into_iter()
.filter(|attr| attr.path.is_ident(ident))
.try_fold(Vec::new(), |mut vec, attr| {
vec.extend(attr.parse_args_with(Punctuated::<T, Token![,]>::parse_terminated)?);
Ok(vec)
})
}