Skip to main content

Crate typewriter_plugin

Crate typewriter_plugin 

Source
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.
FieldDef
A single field inside a struct.
PluginConfig
Configuration data passed to a plugin from typewriter.toml.
StructDef
A complete struct definition in the IR.
VariantDef
A single enum variant.

Enums§

EnumRepr
How the enum is represented in JSON (mirrors serde’s options).
FileStyle
Supported file naming styles.
Language
The target languages that typewriter can generate code for.
PrimitiveType
Rust primitive types that map to language-specific equivalents.
TypeDef
Top-level item — either a struct or an enum.
TypeKind
Every Rust type is mapped to one of these variants.
VariantKind
The kind of data an enum variant carries.

Constants§

PLUGIN_API_VERSION
Current plugin API version.

Traits§

EmitterPlugin
The core trait that every plugin must implement.
TypeMapper
The core trait that every language emitter must implement.

Functions§

to_file_style
Convert a PascalCase name to the specified file style.