typewriter-plugin 1.0.0

Plugin API for typewriter custom language emitters
Documentation

typewriter-plugin

Plugin API for the typewriter type sync SDK.

This crate defines the contract that external language emitter plugins must implement. Plugin authors depend on this crate, implement the [EmitterPlugin] trait, and use the [declare_plugin!] macro to expose C ABI entry points for dynamic loading.

Writing a Plugin

use typewriter_plugin::prelude::*;

struct MyMapper;

impl TypeMapper for MyMapper {
    fn map_primitive(&self, ty: &PrimitiveType) -> String { todo!() }
    fn map_option(&self, inner: &TypeKind) -> String { todo!() }
    fn map_vec(&self, inner: &TypeKind) -> String { todo!() }
    fn map_hashmap(&self, key: &TypeKind, value: &TypeKind) -> String { todo!() }
    fn map_tuple(&self, elements: &[TypeKind]) -> String { todo!() }
    fn map_named(&self, name: &str) -> String { todo!() }
    fn emit_struct(&self, def: &StructDef) -> String { todo!() }
    fn emit_enum(&self, def: &EnumDef) -> String { todo!() }
    fn file_header(&self, type_name: &str) -> String { todo!() }
    fn file_extension(&self) -> &str { todo!() }
    fn file_naming(&self, type_name: &str) -> String { todo!() }
}

struct MyPlugin;

impl EmitterPlugin for MyPlugin {
    fn language_id(&self) -> &str { "mylang" }
    fn language_name(&self) -> &str { "My Language" }
    fn version(&self) -> &str { "0.1.0" }
    fn default_output_dir(&self) -> &str { "./generated/mylang" }
    fn mapper(&self, _config: &PluginConfig) -> Box<dyn TypeMapper> {
        Box::new(MyMapper)
    }
}

declare_plugin!(MyPlugin);