pub struct RestCodegenConfig { /* private fields */ }Expand description
Configuration for REST route code generation.
Decouples the generator from any specific service — all project-specific knowledge (which packages to process, which methods are public) is passed in rather than hardcoded.
§Auto-Discovery
When no packages are registered, generate automatically discovers all
services with google.api.http annotations in the descriptor set, inferring
Rust module paths from proto package names (dots → ::, e.g., auth.v1 →
auth::v1). This matches standard prost-build module generation.
§Examples
Minimal — auto-discovers packages from descriptor set:
let config = RestCodegenConfig::new();
let code = tonic_rest_build::generate(&descriptor_bytes, &config)?;Explicit package mapping (e.g., when using pub use v1::*; re-exports):
let config = RestCodegenConfig::new()
.package("auth.v1", "auth")
.package("users.v1", "users")
.wrapper_type("crate::core::Uuid")
.extension_type("my_app::AuthInfo")
.public_methods(&["Login", "SignUp"]);
let code = tonic_rest_build::generate(&descriptor_bytes, &config)?;Implementations§
Source§impl RestCodegenConfig
impl RestCodegenConfig
Sourcepub fn public_methods(self, methods: &[&str]) -> Self
pub fn public_methods(self, methods: &[&str]) -> Self
Set proto method names whose REST paths bypass authentication.
Method names should be in PascalCase as defined in proto (e.g., "Authenticate").
Sourcepub fn proto_root(self, root: &str) -> Self
pub fn proto_root(self, root: &str) -> Self
Set the root module path for proto-generated types.
Default: "crate" — converts .auth.v1.User → crate::auth::User.
Sourcepub fn runtime_crate(self, path: &str) -> Self
pub fn runtime_crate(self, path: &str) -> Self
Set the runtime crate/module path for generated handler imports.
Default: "tonic_rest" — generates tonic_rest::RestError, etc.
Set to "crate::rest" if the runtime types live alongside the generated code.
Sourcepub fn wrapper_type(self, type_path: &str) -> Self
pub fn wrapper_type(self, type_path: &str) -> Self
Set the Rust type path for single-field wrapper messages.
Required when proto paths contain nested params like {user_id.value}.
Commonly used for UUID wrapper types. Without this, generate
returns a GenerateError for nested path params.
Sourcepub fn sse_keep_alive_secs(self, secs: u64) -> Self
pub fn sse_keep_alive_secs(self, secs: u64) -> Self
Set the SSE keep-alive interval in seconds (default: 15).
Values less than 1 are clamped to 1 to prevent continuous keep-alive spam.
Sourcepub fn extension_type(self, type_path: &str) -> Self
pub fn extension_type(self, type_path: &str) -> Self
Set the extension type extracted from Axum request extensions.
When set, generated handlers use Option<Extension<T>> to extract
the value and forward it to build_tonic_request. Typically used
for auth info (e.g., "my_app::AuthInfo").
When None, handlers skip extension extraction entirely.
§Example
config.extension_type("my_app::AuthInfo")Sourcepub fn extra_forwarded_headers(self, headers: &[&str]) -> Self
pub fn extra_forwarded_headers(self, headers: &[&str]) -> Self
Add extra HTTP headers to forward from REST requests to gRPC metadata.
These are combined with the default FORWARDED_HEADERS at startup.
Use for vendor-specific headers like Cloudflare’s cf-connecting-ip.
§Example
// Forward Cloudflare client IP header
config.extra_forwarded_headers(&["cf-connecting-ip"])Trait Implementations§
Source§impl Clone for RestCodegenConfig
impl Clone for RestCodegenConfig
Source§fn clone(&self) -> RestCodegenConfig
fn clone(&self) -> RestCodegenConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RestCodegenConfig
impl Debug for RestCodegenConfig
Auto Trait Implementations§
impl Freeze for RestCodegenConfig
impl RefUnwindSafe for RestCodegenConfig
impl Send for RestCodegenConfig
impl Sync for RestCodegenConfig
impl Unpin for RestCodegenConfig
impl UnwindSafe for RestCodegenConfig
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> 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