rustc_plugin

Trait RustcPlugin

Source
pub trait RustcPlugin: Sized {
    type Args: Serialize + DeserializeOwned;

    // Required methods
    fn version(&self) -> Cow<'static, str>;
    fn driver_name(&self) -> Cow<'static, str>;
    fn args(&self, target_dir: &Utf8Path) -> RustcPluginArgs<Self::Args>;
    fn run(
        self,
        compiler_args: Vec<String>,
        plugin_args: Self::Args,
    ) -> Result<()>;

    // Provided methods
    fn reported_driver_version(&self) -> Cow<'static, str> { ... }
    fn hash_config(&self, _args: &Self::Args, _hasher: &mut impl Hasher) { ... }
    fn modify_cargo(&self, _cargo: &mut Command, _args: &Self::Args) { ... }
}
Expand description

Interface between your plugin and the rustc_plugin framework.

Required Associated Types§

Source

type Args: Serialize + DeserializeOwned

Command-line arguments passed by the user.

Required Methods§

Source

fn version(&self) -> Cow<'static, str>

Returns the version of your plugin.

A sensible default is your plugin’s Cargo version:

env!("CARGO_PKG_VERSION").into()
Source

fn driver_name(&self) -> Cow<'static, str>

Returns the name of your driver binary as it’s installed in the filesystem.

Should be just the filename, not the full path.

Source

fn args(&self, target_dir: &Utf8Path) -> RustcPluginArgs<Self::Args>

Parses and returns the CLI arguments for the plugin.

Source

fn run(self, compiler_args: Vec<String>, plugin_args: Self::Args) -> Result<()>

Executes the plugin with a set of compiler and plugin args.

Provided Methods§

Source

fn reported_driver_version(&self) -> Cow<'static, str>

Source

fn hash_config(&self, _args: &Self::Args, _hasher: &mut impl Hasher)

Source

fn modify_cargo(&self, _cargo: &mut Command, _args: &Self::Args)

Optionally modify the cargo command that launches rustc. For example, you could pass a --feature flag here.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§