Skip to main content

generate_code

Function generate_code 

Source
pub fn generate_code(
    metadata: &CodeGenMetadata,
    config: &CodeGenConfig,
) -> Result<()>
Expand description

Generate all code described by config from metadata.

Writes the following outputs, depending on which CodeGenOutput fields are Some:

FieldContents
output.commonAxum request extractors (extractors/<service>/) and their mod.rs
output.modelslabels.rs (with generate_resource_enum), pyo3_impls.rs (with output.python) and the mod.rs mounting the models, in the models_subdir
output.serverHandler trait + Axum route wiring per service
output.clientHTTP (and/or ConnectRPC) client structs and request builders per service, plus the aggregate client
output.pythonPyO3 binding wrappers (and the Python package files)
output.nodeNAPI binding wrappers
output.node_tsTypeScript client (client.ts, models/index.ts)
output.wasm#[wasm_bindgen] bindings (mod.rs) and client.d.ts

§Required fields

  • output.server needs output.common (the extractors).
  • bindings must be Some when any of output.python, output.node, or output.node_ts is Some; otherwise returns Error::MissingBindingsConfig.
  • models_path_template and models_path_crate_template must be valid Rust path templates (containing {service}); invalid templates return Error::InvalidModelsPathTemplate.

§Optional fields

Setting generate_resource_enum to false skips labels.rs generation. Setting bindings to None skips all language-binding output.

Call CodeGenConfig::validate before this function to surface config errors at construction time rather than mid-generation.

§Errors

Returns: