pub struct CodeGenConfig {Show 17 fields
pub context_type_path: String,
pub result_type_path: String,
pub models_path_template: String,
pub models_path_crate_template: String,
pub output: CodeGenOutput,
pub generate_resource_enum: bool,
pub generate_store_integration: bool,
pub error_type_path: Option<String>,
pub generate_object_conversions: bool,
pub bindings: Option<BindingsConfig>,
pub resource_store_crate_name: String,
pub runtime: Runtime,
pub transport_type_path: String,
pub dual_transport: bool,
pub client_protocols: ClientProtocols,
pub connect_client_path: Option<String>,
pub rest_client: RestClientOptions,
}Expand description
Configuration for code generation, including import paths and output directories.
Construct this struct directly and set the fields you need.
Fields§
§context_type_path: StringFully-qualified path to the request context type used in handler methods.
No library default; trestle generate uses "crate::api::RequestContext" unless
generate.server.context_type is set.
result_type_path: StringFully-qualified path to the Result alias used in generated handler and client code.
The clients use the Result of the generated error module instead when
RestClientOptions::error_module is set.
No library default; trestle generate uses "crate::Result" unless
generate.server.result_type is set.
models_path_template: StringTemplate for the external model import path. {service} is replaced with the service’s
base path (e.g. "catalogs").
Example: "my_common::models::{service}::v1"
models_path_crate_template: StringTemplate for crate-local model import path. {service} is replaced with the service’s
base path.
Default: "crate::models::{service}::v1"
output: CodeGenOutputOutput directory configuration.
generate_resource_enum: boolWhen true, generate labels.rs with Resource / ObjectLabel enums derived
from google.api.resource annotations. Requires output.models to be Some.
Store-specific output (Label impl, RESOURCE_DESCRIPTORS) is only emitted when
generate_store_integration is also true.
generate_store_integration: boolWhen true (and generate_resource_enum is set), emit the olai_store integration
code in labels.rs:
impl olai_store::Label for ObjectLabelpub static RESOURCE_DESCRIPTORS: &[olai_store::ResourceTypeDescriptor<ObjectLabel>]
Set to false for crates that use the enums without a store dependency.
error_type_path: Option<String>Fully-qualified path to the Error type used in generated TryFrom<Resource> impls.
E.g. "crate::Error". When None, TryFrom impls are not generated.
generate_object_conversions: boolWhen true and generate_resource_enum is set, emit TryFrom<Object>/TryFrom<T>
and ResourceExt impl blocks in labels.rs for all resource types that have an
IDENTIFIER-annotated field, plus a qualified_name() inherent method on each
resource type.
bindings: Option<BindingsConfig>Configuration for language-binding generation. Required when output.python,
output.node, or output.node_ts is Some.
resource_store_crate_name: StringCrate name for the resource store types used in generated RESOURCE_DESCRIPTORS.
Default: "olai_store"
runtime: RuntimeProtobuf runtime the generated code is shaped for. See Runtime.
Defaults to Runtime::Prost for backward compatibility.
transport_type_path: StringFully-qualified path to the HTTP transport type that generated clients store and call.
The transport must expose the surface generated client bodies use: per-verb builder
methods (get/post/patch/delete/put) returning a request builder with
.json(..)/.query(..)/.send(), whose response has .status()/.bytes().
olai_http::CloudClient satisfies this.
Defaults to "olai_http::CloudClient", so native output is unchanged. A WASM/browser
client points this at a lightweight reqwest-Fetch transport that has no ring/tokio
dependency and lets the browser attach the session.
dual_transport: boolForce dual-transport client emission (the cfg-gated CloudClient/WasmClient
Transport alias) even when no WASM #[wasm_bindgen] bindings output is
configured. See dual_transport.
Defaults to false. Setting output.wasm also turns dual-transport on;
this flag exists so a project can build the same client crate for native
and wasm32 without pulling in the JS binding layer.
client_protocols: ClientProtocolsWhich client protocol layer(s) to emit. See ClientProtocols.
Defaults to REST only, so existing HTTP/JSON output is unchanged.
connect_client_path: Option<String>Import path of the connect-rust (BSR plugin) generated client module, used only when
client_protocols includes Connect.
The generated Connect builder layer references the connect-rust client type as
<connect_client_path>::{Service}Client. The path should resolve to the module that
holds the per-service {Service}Client<T> structs (e.g.
"headwaters_proto::connect_gen::headwaters::read::v1").
Required (non-None) whenever Connect is selected and client output is enabled; ignored for
REST-only output.
rest_client: RestClientOptionsWire-format and error options of the REST client. See RestClientOptions.
Implementations§
Source§impl CodeGenConfig
impl CodeGenConfig
Sourcepub fn uses_default_transport(&self) -> bool
pub fn uses_default_transport(&self) -> bool
Whether generated clients use the default cloud transport (olai_http::CloudClient).
Controls emission of cloud-specific aggregate constructors (new_unauthenticated,
new_with_token), which only make sense for CloudClient. A custom transport (e.g. the
WASM/browser one) gets only the generic new(transport, base_url).
Sourcepub fn uses_reqwest_transport(&self) -> bool
pub fn uses_reqwest_transport(&self) -> bool
Whether generated clients use the generated reqwest transport
(REQWEST_TRANSPORT_TYPE_PATH).
Sourcepub fn builds_for_wasm(&self) -> bool
pub fn builds_for_wasm(&self) -> bool
Whether the generated client also builds for wasm32, where the transport’s futures are
not Send, so the builders box them as Local* there.
Sourcepub fn dual_transport(&self) -> bool
pub fn dual_transport(&self) -> bool
Whether the generated client should carry both transports, selected at
compile time by cfg(target_arch = "wasm32") — CloudClient for native
targets, olai_http_wasm::WasmClient for the browser.
Enabled when WASM bindings output is requested (output.wasm), or when
dual_transport is set explicitly: a project that
wants a browser client needs the same client crate to build both ways
(native for server-side/tests, wasm32 for the frontend). Native-only
projects leave both unset and keep the single
transport_type_path transport with no WASM
dependency.
The explicit flag decouples the transport alias from the JS binding layer:
output.wasm additionally emits #[wasm_bindgen] bindings, whereas
dual_transport = true alone emits only the cfg-gated Transport alias.
Sourcepub fn json_int64_module_path(&self) -> Option<String>
pub fn json_int64_module_path(&self) -> Option<String>
The crate-local path of the json_int64 module (e.g. crate::models::json_int64), for
ModelRewrites::int64_module. None
unless RestClientOptions::json_int64_as_number is set.
Sourcepub fn json_value_module_path(&self) -> Option<String>
pub fn json_value_module_path(&self) -> Option<String>
The crate-local path of the json_value module (e.g. crate::models::json_value), for
ModelRewrites::json_value_module.
None unless RestClientOptions::json_int64_as_number is set.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate this config without running code generation.
Checks that:
models_path_templateandmodels_path_crate_templateproduce valid Rust paths after{service}substitution.context_type_pathandresult_type_pathparse as Rust paths.bindingsisSomewheneveroutput.python,output.node,output.node_ts, oroutput.wasmisSome;output.pythonalso needsBindingsConfig::python.- language bindings have the REST client protocol enabled.
- the Connect client has a
connect_client_path. - the REST client and Python options that need other options have them.
generate_code runs the same checks, so calling this first only
moves the error to construction time.
Trait Implementations§
Source§impl Clone for CodeGenConfig
impl Clone for CodeGenConfig
Auto Trait Implementations§
impl Forget for CodeGenConfig
impl Freeze for CodeGenConfig
impl RefUnwindSafe for CodeGenConfig
impl Send for CodeGenConfig
impl Sync for CodeGenConfig
impl Unpin for CodeGenConfig
impl UnsafeUnpin for CodeGenConfig
impl UnwindSafe for CodeGenConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more