Skip to main content

TranspilerPlugin

Trait TranspilerPlugin 

Source
pub trait TranspilerPlugin: Send + Sync {
    // Required methods
    fn metadata(&self) -> PluginMetadata;
    fn transpile(&self, source: &str, language: Language) -> Result<String>;

    // Provided methods
    fn initialize(&mut self) -> Result<()> { ... }
    fn transpile_file(&self, path: &Path, language: Language) -> Result<String> { ... }
    fn validate(&self, _original: &str, _transpiled: &str) -> Result<()> { ... }
    fn cleanup(&mut self) -> Result<()> { ... }
}
Expand description

Core trait for transpiler plugins

Implement this trait to create custom transpilers that integrate with Batuta’s pipeline.

Required Methods§

Source

fn metadata(&self) -> PluginMetadata

Get plugin metadata

Source

fn transpile(&self, source: &str, language: Language) -> Result<String>

Transpile source code to Rust

§Arguments
  • source - Source code to transpile
  • language - Source language
§Returns

Rust code as a String

Provided Methods§

Source

fn initialize(&mut self) -> Result<()>

Initialize the plugin

Called once when the plugin is loaded. Use this for setup tasks like:

  • Loading configuration
  • Initializing caches
  • Validating dependencies
Source

fn transpile_file(&self, path: &Path, language: Language) -> Result<String>

Transpile a file

Default implementation reads the file and calls transpile(). Override for custom file handling (e.g., imports, multi-file projects).

Source

fn validate(&self, _original: &str, _transpiled: &str) -> Result<()>

Validate transpiled output

Optional validation hook. Override to add custom validation logic.

Source

fn cleanup(&mut self) -> Result<()>

Cleanup resources

Called when the plugin is unloaded or the pipeline completes.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§