Skip to main content

proto_path_to_axum

Function proto_path_to_axum 

Source
pub fn proto_path_to_axum(path: &str) -> String
Expand description

Convert a google.api.http path template to axum 0.8 path syntax.

The proto {param} form IS axum 0.8’s native capture syntax, so plain single-segment params pass through verbatim. Only field-path templates and bare wildcards need rewriting (axum 0.7 used :param; 0.8 uses {param} and rejects any segment starting with :):

  • {name=*} (single segment) -> {name}
  • {name=**} (multi-segment) -> {*name} (axum catch-all)
  • bare * segment -> {N}, N its segment index
  • bare ** segment -> {*N} (axum catch-all)

A custom verb after a variable or wildcard ({name}:cancel) is not part of the result: axum cannot match it, so the transcoded router checks it itself. A verb after a literal (/v1/nodes:batch) stays in that literal.