Add type alias support for plugin modules.

This commit is contained in:
Stephen Chung
2022-03-19 09:43:18 +08:00
parent 6546eae95f
commit fefa633cf0
12 changed files with 207 additions and 18 deletions

View File

@@ -18,9 +18,17 @@ pub struct ExportedConst {
pub cfg_attrs: Vec<syn::Attribute>,
}
#[derive(Debug)]
pub struct ExportedType {
pub name: String,
pub typ: Box<syn::Type>,
pub cfg_attrs: Vec<syn::Attribute>,
}
pub fn generate_body(
fns: &mut [ExportedFn],
consts: &[ExportedConst],
custom_types: &[ExportedType],
sub_modules: &mut [Module],
parent_scope: &ExportScope,
) -> TokenStream {
@@ -54,6 +62,29 @@ pub fn generate_body(
);
}
for ExportedType {
name,
typ,
cfg_attrs,
..
} in custom_types
{
let const_literal = syn::LitStr::new(&name, Span::call_site());
let cfg_attrs: Vec<_> = cfg_attrs
.iter()
.map(syn::Attribute::to_token_stream)
.collect();
set_const_statements.push(
syn::parse2::<syn::Stmt>(quote! {
#(#cfg_attrs)*
m.set_custom_type::<#typ>(#const_literal);
})
.unwrap(),
);
}
for item_mod in sub_modules {
item_mod.update_scope(&parent_scope);
if item_mod.skipped() {