Expand description
UniStructGen Core Library
This crate provides the core types and traits for UniStructGen:
- IR (Intermediate Representation): Language-agnostic type system
- Parser trait: Interface for implementing parsers for different formats
- CodeGenerator trait: Interface for implementing code generators for different languages
- Transformer trait: Interface for transforming IR between parsing and generation
- Pipeline: Composable processing pipeline with transformers
- Plugin system: Extensible plugin architecture for custom processing
- Error types: Common error handling infrastructure
§Architecture
UniStructGen follows a plugin-based pipeline architecture:
Input → [Plugins] → Parser → IR → Transformers → Generator → [Plugins] → OutputThe core library provides the foundation for this pipeline through traits and data structures that ensure type safety and composability.
§Examples
§Basic usage with a parser and generator:
ⓘ
use unistructgen_core::{Parser, CodeGenerator};
// Create parser and generator
let mut parser = MyParser::new();
let generator = MyGenerator::new();
// Parse input
let ir_module = parser.parse(input)?;
// Generate code
let code = generator.generate(&ir_module)?;§Using the Pipeline API:
ⓘ
use unistructgen_core::{Pipeline, transformer::FieldOptionalizer};
let mut pipeline = Pipeline::new(parser, generator)
.add_transformer(Box::new(FieldOptionalizer::new()));
let code = pipeline.execute(input)?;§Using Plugins:
ⓘ
use unistructgen_core::{PluginRegistry, plugin::LoggingPlugin};
let mut registry = PluginRegistry::new();
registry.register(Box::new(LoggingPlugin::new(true)))?;
// Use plugins in your processing pipeline
let input = registry.before_parse(input)?;
let module = registry.after_parse(module)?;
let code = registry.after_generate(code)?;Re-exports§
pub use into_ir::IntoIR;pub use parser::Parser;pub use parser::ParserExt;pub use parser::ParserMetadata;pub use parser::ParserResult;pub use codegen::CodeGenerator;pub use codegen::CodeGeneratorExt;pub use codegen::GeneratorMetadata;pub use codegen::CodegenResult;pub use codegen::MultiGenerator;pub use transformer::IRTransformer;pub use transformer::TransformError;pub use pipeline::Pipeline;pub use pipeline::PipelineBuilder;pub use pipeline::PipelineError;pub use plugin::Plugin;pub use plugin::PluginRegistry;pub use plugin::PluginError;pub use visitor::IRVisitor;pub use visitor::walk_module;pub use visitor::walk_type;pub use visitor::walk_struct;pub use visitor::walk_field;pub use visitor::walk_type_ref;pub use tools::AiTool;pub use tools::ToolRegistry;pub use tools::ToolError;pub use tools::ToolResult;pub use context::Context;pub use api::StructGen;pub use api::EnumGen;pub use api::ModuleGen;pub use api::FieldBuilder;pub use api::FieldType;pub use api::RenderOptions as ApiRenderOptions;pub use api::ApiResult;pub use api::ApiError;pub use api::from_json;pub use api::JsonGenBuilder;pub use api::render_module;pub use api::render_module_with_options;pub use ir::*;pub use error::*;pub use validation::*;
Modules§
- api
- Unified API for struct generation
- codegen
- Code generator trait and related types
- context
- diagnostics
- error
- into_ir
- ir
- parser
- Parser trait and related types
- patch
- pipeline
- Pipeline architecture for processing data through multiple stages
- plugin
- Plugin system for extending functionality
- tools
- transformer
- IR transformation infrastructure
- validation
- visitor
- Visitor pattern for traversing and modifying IR