use proc_macro::TokenStream;
use syn::{parse_macro_input, Expr, ItemStruct};
use super::{inter_struct_base, Mode};
use crate::helper::get_root_src_path;
use crate::parse;
pub mod normal;
pub fn struct_into_inner(struct_ast: TokenStream) -> TokenStream {
let src_struct = parse_macro_input!(struct_ast as ItemStruct);
let src_root_path = match get_root_src_path(&src_struct) {
Ok(path) => path,
Err(err) => return TokenStream::from(err),
};
let attribute = match parse::attribute(&src_struct, "StructInto", "struct_into") {
Ok(attribute) => attribute,
Err(err) => return TokenStream::from(err),
};
let attribute_args = TokenStream::from(attribute.tokens);
let parsed_args = parse_macro_input!(attribute_args as Expr);
let impls = inter_struct_base(&src_root_path, &src_struct, parsed_args, Mode::Into);
let mut tokens = TokenStream::new();
tokens.extend(impls.into_iter().map(TokenStream::from));
#[cfg(feature = "debug")]
println!("StructInto impl: {}", tokens.to_string());
tokens
}
pub fn struct_into_default_inner(struct_ast: TokenStream) -> TokenStream {
let src_struct = parse_macro_input!(struct_ast as ItemStruct);
let src_root_path = match get_root_src_path(&src_struct) {
Ok(path) => path,
Err(err) => return TokenStream::from(err),
};
let attribute = match parse::attribute(&src_struct, "StructInto", "struct_into_default") {
Ok(attribute) => attribute,
Err(err) => return TokenStream::from(err),
};
let attribute_args = TokenStream::from(attribute.tokens);
let parsed_args = parse_macro_input!(attribute_args as Expr);
let impls = inter_struct_base(&src_root_path, &src_struct, parsed_args, Mode::IntoDefault);
let mut tokens = TokenStream::new();
tokens.extend(impls.into_iter().map(TokenStream::from));
#[cfg(feature = "debug")]
println!("StructInto impl: {}", tokens.to_string());
tokens
}