mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-06-06 05:49:01 +08:00
Update
This commit is contained in:
@@ -9,6 +9,7 @@ use syn::token;
|
||||
use syn::Block;
|
||||
use syn::Expr;
|
||||
use syn::Ident;
|
||||
use syn::ItemEnum;
|
||||
use syn::ItemFn;
|
||||
use syn::Lit;
|
||||
use syn::LitBool;
|
||||
@@ -580,3 +581,42 @@ pub fn check_json_keys(item: TokenStream) -> TokenStream {
|
||||
);
|
||||
stream.into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(CheckUnkown)]
|
||||
pub fn derive_check_unknown(item: TokenStream) -> TokenStream {
|
||||
let ItemEnum {
|
||||
attrs: _,
|
||||
vis: _,
|
||||
enum_token: _,
|
||||
ident,
|
||||
generics: _,
|
||||
brace_token: _,
|
||||
variants,
|
||||
} = parse_macro_input!(item as ItemEnum);
|
||||
let mut streams = Vec::new();
|
||||
for i in variants.iter() {
|
||||
let ident = i.ident.clone();
|
||||
let s = ident.to_string();
|
||||
if s == "Unknown" {
|
||||
streams.push(
|
||||
quote!(Self::#ident(data) => Err(crate::fanbox::error::FanboxAPIError::from(format!(
|
||||
"{} {}",
|
||||
crate::gettext("Failed to recognize type:"),
|
||||
data
|
||||
))),),
|
||||
);
|
||||
} else {
|
||||
streams.push(quote!(Self::#ident(tmp) => crate::fanbox::check::CheckUnkown::check_unknown(tmp),));
|
||||
}
|
||||
}
|
||||
let stream = quote!(
|
||||
impl crate::fanbox::check::CheckUnkown for #ident {
|
||||
fn check_unknown(&self) -> Result<(), crate::fanbox::error::FanboxAPIError> {
|
||||
match self {
|
||||
#(#streams)*
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
stream.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user