{%- if doc %}
{{ doc }}{%- endif %}
public func {{ variant_name }}(_ handler: @escaping (String) -> String{% if signature_params %}, {% for param in signature_params %}{{ param.name }}: {{ param.swift_type }}{{ "," if not loop.last else "" }}{% endfor %}{% endif %}{% for option in options %}, {{ option.name }}: {{ option.swift_type }}? = nil{% endfor %}) throws {
// Construct the wrapper metadata param (e.g. RouteBuilder) from the fixed enum arg
// and any free args. swift-bridge generates enums as opaque classes — there are no
// static member constants (e.g. `RustBridge.Method.Get` is invalid). Instead,
// each opaque enum type has a `<type>FromJson` factory that parses a serde JSON
// string into an opaque instance. The wrapper constructor factory `{{ factory_fn_camel }}`
// is a bridge-declared free function that calls the Rust wrapper's `new` method.
{{ "var" if options else "let" }} __builder = RustBridge.{{ factory_fn_camel }}({{ factory_args_str }})
{% for option in options %}
// Chain the optional `{{ option.name }}` metadata onto the wrapper before delegating, so
// the shortcut can express everything the builder can and not just its constructor args.
if let {{ option.name }} {
__builder = RustBridge.{{ option.bridge_fn_camel }}(__builder, {{ option.into_rust_expr }})
}
{% endfor %}
// Delegate to the base registration method, passing the constructed wrapper as the
// `{{ base_param_name }}` metadata param. This reuses all the handler boxing and
// trampoline logic from the base method without duplicating it.
try {{ base_method_camel }}(handler, {{ base_param_name }}: __builder)
}