MacroPlugin

Trait MacroPlugin 

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

    // Provided methods
    fn declared_derives<'db>(
        &self,
        _db: &'db dyn Database,
    ) -> Vec<SmolStrId<'db>> { ... }
    fn executable_attributes<'db>(
        &self,
        _db: &'db dyn Database,
    ) -> Vec<SmolStrId<'db>> { ... }
    fn phantom_type_attributes<'db>(
        &self,
        _db: &'db dyn Database,
    ) -> Vec<SmolStrId<'db>> { ... }
    fn plugin_type_id(&self) -> TypeId { ... }
}
Expand description

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

Required Methods§

Source

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

Generates code for an item. If no code should be generated returns None. Otherwise, returns PluginResult with the generated virtual submodule.

Source

fn declared_attributes<'db>(&self, db: &'db dyn Database) -> Vec<SmolStrId<'db>>

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<'db>(&self, _db: &'db dyn Database) -> Vec<SmolStrId<'db>>

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<'db>( &self, _db: &'db dyn Database, ) -> Vec<SmolStrId<'db>>

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<'db>( &self, _db: &'db dyn Database, ) -> Vec<SmolStrId<'db>>

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

Source

fn plugin_type_id(&self) -> TypeId

A TypeId of the plugin, used to compare the concrete types of plugins given as trait objects.

Implementors§