cairo_lang_defs::plugin

Trait MacroPlugin

Source
pub trait MacroPlugin:
    Debug
    + Sync
    + Send {
    // Required methods
    fn generate_code(
        &self,
        db: &dyn SyntaxGroup,
        item_ast: ModuleItem,
        metadata: &MacroPluginMetadata<'_>,
    ) -> PluginResult;
    fn declared_attributes(&self) -> Vec<String>;

    // Provided methods
    fn declared_derives(&self) -> Vec<String> { ... }
    fn executable_attributes(&self) -> Vec<String> { ... }
    fn phantom_type_attributes(&self) -> Vec<String> { ... }
}
Expand description

A trait for a macro plugin: external plugin that generates additional code for items.

Required Methods§

Source

fn generate_code( &self, db: &dyn SyntaxGroup, item_ast: ModuleItem, metadata: &MacroPluginMetadata<'_>, ) -> PluginResult

Generates code for an item. If no code should be generated returns None. Otherwise, returns (virtual_module_name, module_content), and a virtual submodule with that name and content should be created.

Source

fn declared_attributes(&self) -> Vec<String>

Attributes this plugin uses. Attributes the plugin uses without declaring here are likely to cause a compilation error for unknown attribute. Note: They may not cause a diagnostic if some other plugin declares such attribute, but plugin writers should not rely on that.

Provided Methods§

Source

fn declared_derives(&self) -> Vec<String>

Derives this plugin supplies. Any derived classes the plugin supplies without declaring here are likely to cause a compilation error for unknown derive. Note: They may not cause a diagnostic if some other plugin declares such derive, but plugin writers should not rely on that.

Source

fn executable_attributes(&self) -> Vec<String>

Attributes that should mark the function as an executable. Functions marked with executable attributes will be listed in a dedicated field in the generated program. Must return a subset of declared_attributes. This mechanism is optional.

Source

fn phantom_type_attributes(&self) -> Vec<String>

Attributes that mark a type as a phantom type. Must return a subset of declared_attributes. This mechanism is optional.

Implementors§