Skip to content

Router::route_* manual routing is stringly typed and surfaces in rustdoc before the codegen path #91

@iainmcgin

Description

@iainmcgin

Router exposes a family of stringly-typed route_* methods:

pub fn route(self, service_name: &str, method_name: &str, handler: ...) -> Self
pub fn route_view_idempotent(self, service_name: &str, method_name: &str, handler: ...) -> Self
pub fn route_view_server_stream(...)
pub fn route_view_client_stream(...)
pub fn route_view_bidi_stream(...)
// ... 8 variants total

A typo in service_name or method_name produces a runtime Unimplemented for clients — not a compile error. The generated <Service>Ext::register path avoids this entirely (it passes the *_SERVICE_NAME constants), but the manual route_* family is what shows up first in Router's rustdoc, so it's the API new users see and the one that invites the bug.

These methods are essentially codegen plumbing. They need to remain pub so generated code can call them, but they shouldn't be the documented entry point for end users.

Proposed direction

  • #[doc(hidden)] on the route_* family, with a doc note pointing at the generated register extension trait as the supported path.
  • If a manual-routing escape hatch is genuinely needed (e.g. proxies that route without codegen), expose one that takes typed arguments — a MethodDescriptor/Spec struct rather than two &strs — so a typo is at least a MethodDescriptor construction error rather than a silent Unimplemented.
  • Consider collapsing the 8 route_view_* variants into one route_view::<...>(spec, handler) form that takes an RpcKind enum, reducing the surface even on the codegen side.

Scope

Small (#[doc(hidden] + doc updates), or medium if we also collapse the variants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions