Skip to main content

ironsbe_codegen/
lib.rs

1//! # IronSBE Codegen
2//!
3//! Code generation from SBE XML schemas.
4//!
5//! This crate provides:
6//! - Rust code generation from SBE schemas
7//! - Message encoder/decoder generation
8//! - Type and enum generation
9//! - Build script integration
10
11pub mod error;
12pub mod generator;
13pub mod rust;
14
15pub use error::CodegenError;
16pub use generator::Generator;
17
18/// Generates Rust code from an SBE XML schema string.
19///
20/// # Arguments
21/// * `xml` - SBE XML schema content
22///
23/// # Returns
24/// Generated Rust code as a string.
25///
26/// # Errors
27/// Returns `CodegenError` if parsing or generation fails.
28pub fn generate_from_xml(xml: &str) -> Result<String, CodegenError> {
29    let schema = ironsbe_schema::parse_schema(xml)?;
30    let ir = ironsbe_schema::SchemaIr::from_schema(&schema);
31    let generator = Generator::new(&ir);
32    Ok(generator.generate())
33}
34
35/// Generates Rust code from an SBE XML schema file.
36///
37/// # Arguments
38/// * `path` - Path to the SBE XML schema file
39///
40/// # Returns
41/// Generated Rust code as a string.
42///
43/// # Errors
44/// Returns `CodegenError` if reading, parsing, or generation fails.
45pub fn generate_from_file(path: &std::path::Path) -> Result<String, CodegenError> {
46    let xml = std::fs::read_to_string(path)?;
47    generate_from_xml(&xml)
48}