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§
Sourcetype Config: PluginConfig
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§
Sourcefn apply(&self, ctx: &mut GenerateContext, config: &Self::Config) -> Result<()>
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§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Stable plugin identifier, used in:
after()/before()cross-references- The mutation journal
- Error messages
- The
PluginRequestenvelope’snamefield
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.
Sourcefn after(&self) -> &'static [&'static str]
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).
Sourcefn before(&self) -> &'static [&'static str]
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.
Sourcefn validate(&self, _config: &Self::Config) -> Result<()>
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".