unistructgen_core/lib.rs
1//! UniStructGen Core Library
2//!
3//! This crate provides the core types and traits for UniStructGen:
4//! - **IR (Intermediate Representation)**: Language-agnostic type system
5//! - **Parser trait**: Interface for implementing parsers for different formats
6//! - **CodeGenerator trait**: Interface for implementing code generators for different languages
7//! - **Transformer trait**: Interface for transforming IR between parsing and generation
8//! - **Pipeline**: Composable processing pipeline with transformers
9//! - **Plugin system**: Extensible plugin architecture for custom processing
10//! - **Error types**: Common error handling infrastructure
11//!
12//! # Architecture
13//!
14//! UniStructGen follows a plugin-based pipeline architecture:
15//!
16//! ```text
17//! Input → [Plugins] → Parser → IR → Transformers → Generator → [Plugins] → Output
18//! ```
19//!
20//! The core library provides the foundation for this pipeline through traits
21//! and data structures that ensure type safety and composability.
22//!
23//! # Examples
24//!
25//! ## Basic usage with a parser and generator:
26//!
27//! ```ignore
28//! use unistructgen_core::{Parser, CodeGenerator};
29//!
30//! // Create parser and generator
31//! let mut parser = MyParser::new();
32//! let generator = MyGenerator::new();
33//!
34//! // Parse input
35//! let ir_module = parser.parse(input)?;
36//!
37//! // Generate code
38//! let code = generator.generate(&ir_module)?;
39//! ```
40//!
41//! ## Using the Pipeline API:
42//!
43//! ```ignore
44//! use unistructgen_core::{Pipeline, transformer::FieldOptionalizer};
45//!
46//! let mut pipeline = Pipeline::new(parser, generator)
47//! .add_transformer(Box::new(FieldOptionalizer::new()));
48//!
49//! let code = pipeline.execute(input)?;
50//! ```
51//!
52//! ## Using Plugins:
53//!
54//! ```ignore
55//! use unistructgen_core::{PluginRegistry, plugin::LoggingPlugin};
56//!
57//! let mut registry = PluginRegistry::new();
58//! registry.register(Box::new(LoggingPlugin::new(true)))?;
59//!
60//! // Use plugins in your processing pipeline
61//! let input = registry.before_parse(input)?;
62//! let module = registry.after_parse(module)?;
63//! let code = registry.after_generate(code)?;
64//! ```
65
66pub mod ir;
67pub mod error;
68pub mod parser;
69pub mod codegen;
70pub mod transformer;
71pub mod pipeline;
72pub mod plugin;
73pub mod visitor;
74pub mod api;
75pub mod validation;
76pub mod tools;
77pub mod context;
78pub mod diagnostics;
79pub mod patch;
80pub mod into_ir;
81
82// Re-export main types and traits
83pub use ir::*;
84pub use into_ir::IntoIR;
85pub use error::*;
86pub use parser::{Parser, ParserExt, ParserMetadata, ParserResult};
87pub use codegen::{CodeGenerator, CodeGeneratorExt, GeneratorMetadata, CodegenResult, MultiGenerator};
88pub use transformer::{IRTransformer, TransformError};
89pub use pipeline::{Pipeline, PipelineBuilder, PipelineError};
90pub use plugin::{Plugin, PluginRegistry, PluginError};
91pub use visitor::{IRVisitor, walk_module, walk_type, walk_struct, walk_field, walk_type_ref};
92pub use validation::*;
93pub use tools::{AiTool, ToolRegistry, ToolError, ToolResult};
94pub use context::Context;
95pub use async_trait::async_trait;
96
97// Re-export unified API for convenient access
98pub use api::{
99 StructGen, EnumGen, ModuleGen,
100 FieldBuilder, FieldType,
101 RenderOptions as ApiRenderOptions,
102 ApiResult, ApiError,
103 from_json, JsonGenBuilder,
104 render_module, render_module_with_options,
105};