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:
- Analysis: Process collected metadata to understand service structure
- Planning: Determine what code needs to be generated
- Generation: Create Rust code using templates and metadata
- 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§
- Bindings
Config - Configuration for language-binding code generation (Python / Node.js).
- Client
Handler Impls 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 onfeatureand left out onwasm32(the client futures are notSendthere). The client error must convert into the handler error (impl From<client::Error> for handlers::Error). The request context is ignored.- Client
Protocols - Which client protocol layer(s) to emit.
- Code
GenConfig - Configuration for code generation, including import paths and output directories.
- Code
GenOutput - Output directory configuration for code generation.
- Error
Module Config - 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. - Generated
Code - An in-memory bundle of generated source files awaiting output.
- Models
Path - Validated model import path derived from a
{service}template string. - PyPackage
Config - Where the generated pure-Python files go.
- Python
Options - Shape of the generated Python (PyO3) API.
- Rest
Client Options - Wire-format and error options of the generated REST client. Every option is off by default.
Enums§
- Client
Protocol - 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
reqwesttransport.
Functions§
- generate_
code - Generate all code described by
configfrommetadata. - generate_
models_ mod - Generate the
mod.rsforcrates/common/src/models/. - main_
module