Expand description
§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);Modules§
- prelude
- Convenience prelude for plugin authors.
Macros§
- declare_
plugin - Declare a plugin’s C ABI entry points for dynamic loading.
Structs§
- EnumDef
- A complete enum definition in the IR.
- Field
Def - A single field inside a struct.
- Plugin
Config - Configuration data passed to a plugin from
typewriter.toml. - Struct
Def - A complete struct definition in the IR.
- Variant
Def - A single enum variant.
Enums§
- Enum
Repr - How the enum is represented in JSON (mirrors serde’s options).
- File
Style - Supported file naming styles.
- Language
- The target languages that typewriter can generate code for.
- Primitive
Type - Rust primitive types that map to language-specific equivalents.
- TypeDef
- Top-level item — either a struct or an enum.
- Type
Kind - Every Rust type is mapped to one of these variants.
- Variant
Kind - The kind of data an enum variant carries.
Constants§
- PLUGIN_
API_ VERSION - Current plugin API version.
Traits§
- Emitter
Plugin - The core trait that every plugin must implement.
- Type
Mapper - The core trait that every language emitter must implement.
Functions§
- to_
file_ style - Convert a PascalCase name to the specified file style.