Skip to main content

Module codegen

Module codegen 

Source
Expand description

Code generation module for REST API handlers and language bindings.

This module provides the core functionality for generating Rust code from protobuf metadata extracted from service definitions.

§Architecture

The code generation process follows these phases:

  1. Analysis: Process collected metadata to understand service structure
  2. Planning: Determine what code needs to be generated
  3. Generation: Create Rust code using templates and metadata
  4. Output: Write generated code to appropriate files

§Generated Code Types

  • Handler Traits: Async trait definitions for service operations
  • Request Extractors: Axum FromRequest/FromRequestParts implementations
  • Route Handlers: Axum handler functions that delegate to traits
  • Client Code: HTTP client implementations for services
  • Type Mappings: Conversions between protobuf and Rust types

Structs§

BindingsConfig
Configuration for language-binding code generation (Python / Node.js).
ClientHandlerImpls
impl <Handler> for <ServiceClient> per service, forwarding each trait method to the client method of the same name, so a client serves its service from an upstream server. The impls go in <service>/handler.rs, gated on feature and left out on wasm32 (the client futures are not Send there). The client error must convert into the handler error (impl From<client::Error> for handlers::Error). The request context is ignored.
ClientProtocols
Which client protocol layer(s) to emit.
CodeGenConfig
Configuration for code generation, including import paths and output directories.
CodeGenOutput
Output directory configuration for code generation.
ErrorModuleConfig
Shape of the JSON error body that the generated error module reads, such as {"error_code": "NOT_FOUND", "message": "…", "details": […]}. A body that is not such an object becomes the message.
GeneratedCode
An in-memory bundle of generated source files awaiting output.
ModelsPath
Validated model import path derived from a {service} template string.
PyPackageConfig
Where the generated pure-Python files go.
PythonOptions
Shape of the generated Python (PyO3) API.
RestClientOptions
Wire-format and error options of the generated REST client. Every option is off by default.

Enums§

ClientProtocol
Wire protocol a generated client speaks.
Runtime
Protobuf runtime that the generated code is expected to consume.

Constants§

DEFAULT_TRANSPORT_TYPE_PATH
Default transport type path: the cloud client used by native (non-WASM) generated code.
REQWEST_TRANSPORT_TYPE_PATH
Transport type path that selects the generated reqwest transport.

Functions§

generate_code
Generate all code described by config from metadata.
generate_models_mod
Generate the mod.rs for crates/common/src/models/.
main_module