Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin {
    type Config: PluginConfig;

    // Required method
    fn apply(
        &self,
        ctx: &mut GenerateContext,
        config: &Self::Config,
    ) -> Result<()>;

    // Provided methods
    fn name(&self) -> &'static str { ... }
    fn after(&self) -> &'static [&'static str] { ... }
    fn before(&self) -> &'static [&'static str] { ... }
    fn validate(&self, _config: &Self::Config) -> Result<()> { ... }
}
Expand description

What a plugin implements.

Required Associated Types§

Source

type Config: PluginConfig

Plugin-specific config. The user passes this in via app.plugin::<Self>(|c| c.field(...)) inside whisker.rs — the c parameter is &mut Self::Config.

Required Methods§

Source

fn apply(&self, ctx: &mut GenerateContext, config: &Self::Config) -> Result<()>

Actually mutate the GenerateContext. This is where the plugin reads config, decides what IR fields to touch, and writes them. For each mutation the plugin also calls MutationJournal::record on ctx.journal so the engine can attribute conflicts and produce a verbose summary.

Provided Methods§

Source

fn name(&self) -> &'static str

Stable plugin identifier, used in:

  • after() / before() cross-references
  • The mutation journal
  • Error messages
  • The PluginRequest envelope’s name field

Defaults to Self::Config::NAME so the binding between the plugin’s Config type and the plugin’s name only has to be declared once (on the Config). The override slot is mostly there for tests and shims that want to expose the same Config under a different identifier; production plugins should leave it at the default.

Source

fn after(&self) -> &'static [&'static str]

Plugins this one must run after. Used by the topological sort in whisker-cng::compose. Default: empty (no ordering constraints).

Source

fn before(&self) -> &'static [&'static str]

Plugins this one must run before. Same as Plugin::after but expresses the inverse constraint — useful when you can’t (or don’t want to) modify the downstream plugin’s source.

Source

fn validate(&self, _config: &Self::Config) -> Result<()>

Reject obviously-broken config before any side effects fire. The engine runs this on every plugin before scheduling the apply pass, so a validation failure aborts cleanly without leaving a half-mutated IR behind.

Default: accept everything.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§