Skip to content

fidius-macro::interface

Rust

Code generation for #[plugin_interface].

Generates: the original trait, a #[repr(C)] vtable struct, interface hash constant, capability bit constants, version/strategy constants, and a descriptor builder function.

pub

fn generate_interface(ir: &InterfaceIR) -> syn::Result<TokenStream>

Generate all code for a #[plugin_interface] invocation.

Source
pub fn generate_interface(ir: &InterfaceIR) -> syn::Result<TokenStream> {
// Both PluginAllocated and Arena are supported; vtable and shim codegen
// branches on ir.attrs.buffer_strategy.
match ir.attrs.buffer_strategy {
BufferStrategyAttr::PluginAllocated | BufferStrategyAttr::Arena => {}
}
let cleaned_trait = strip_optional_attrs(&ir.original_trait);
let vtable = generate_vtable(ir);
let constants = generate_constants(ir);
let descriptor_builder = generate_descriptor_builder(ir);
let method_indices = generate_method_indices(ir);
let metadata = generate_metadata(ir);
let client = generate_client(ir);
let companion_mod = format_ident!("__fidius_{}", ir.trait_name);
Ok(quote! {
#cleaned_trait
/// Generated companion module for the plugin interface.
///
/// Contains the VTable struct, interface hash, capability constants,
/// vtable constructor, descriptor builder, and method index constants.
/// Method indices follow trait declaration order (0-based).
#[allow(non_snake_case, non_upper_case_globals, dead_code)]
pub mod #companion_mod {
use super::*;
#vtable
#constants
#method_indices
#metadata
#descriptor_builder
}
#client
})
}