Skip to content

feat(server): infer route path type via impl AsRef<str> parameter - #43

Merged
vshengbro merged 1 commit into
masterfrom
feat/server-route-infer-path-2026-10-09
Oct 9, 2026
Merged

vshengbro merged 1 commit into
masterfrom
feat/server-route-infer-path-2026-10-09

Conversation

@vshengbro

Copy link
Copy Markdown
Member

Summary

Server::route drops its explicit P generic and takes path: impl AsRef<str> instead:

// before
pub fn route<S, P>(&mut self, path: P) -> &mut Self
where
    S: ServerHook,
    P: AsRef<str>;

// after
pub fn route<S>(&mut self, path: impl AsRef<str>) -> &mut Self
where
    S: ServerHook;

Callers now write server.route::<TestRoute>("/") without naming the path type. The impl AsRef<str> parameter is the inference shim exempted by rust-standards §9.2a, so &str, String and &String call sites keep compiling and method chaining still works.

Breaking change: turbofish call sites that named the path type explicitly (route::<T, &str>(path)) no longer compile — the method now takes exactly one generic argument (E0107). All 42 in-tree call sites are updated in this commit:

  • core/tests/route/fn.rs — 22 call sites + new route_path_type_inference test
  • core/tests/server/fn.rs — 18 call sites
  • plugin/websocket/tests/websocket/fn.rs — 2 call sites

Workspace version bumped 21.11.0 → 21.12.0 ([workspace.package] only; [workspace.dependencies] path versions synced via crate sync). The #[route] proc-macro registers routes via inventory::submit! + HookType::Route and does not call Server::route, so hyperlane-macros is unaffected. hyperlane-cli and the root hyperlane shim never wrap route.

Verification

  • cargo build --workspace — clean
  • cargo clippy --workspace --all-targets — 0 warnings, 0 errors
  • cargo test --workspace --all-features — all pass, 694 assertions total; route::r#fn::route_path_type_inference ... ok covers &str, String, &String and chained registration
  • cargo fmt --all + cargo fmt --all -- --check — 0 diff, idempotent
  • rust-standards audit: 50/51 PASS, identical to the origin/master baseline (the single FAIL is check 49 §18 const-visibility, 2114 pre-existing hits in 12 files on both trees — zero new violations introduced by this change)
  • staged_file_gate.py (pre-commit hook) — 0 new violations, commit allowed
  • Backward-compat probe (not committed): route::<TestRoute, &str>("/") now fails with E0107 as expected — this is the breaking half of the change, which is why the call-site updates and the minor bump ship together

Notes

  • Repo rebased onto eea52fa (PR chore: centralize test std imports into tests mod.rs (§6.4, check 26) #41) before commit; no overlap with that PR's type/tests files.
  • Follow-up after merge: hyperlane-quick-start (master + playground) bumps its hyperlane / hyperlane-core requirement to 21.12.0 once crates.io serves it.
  • The §18 check-49 debt (2114 pub const hits) is pre-existing on master and out of scope here; it needs its own sweep PR.

Drop the explicit P generic from Server::route so callers write
route::<TestRoute>("/") without naming the path type. The path now
arrives as impl AsRef<str> (the inference-shim exemption in
rust-standards section 9.2a), which keeps &str, String and &String
call sites compiling unchanged while removing the mandatory second
turbofish parameter.

BREAKING CHANGE: turbofish call sites that named the path type
explicitly (route::<T, &str>(path)) no longer compile, because the
method now takes exactly one generic argument. All 42 in-tree call
sites in core/tests and plugin/websocket/tests were updated in this
commit, and a new route_path_type_inference test proves &str,
String, &String and chained registration all infer correctly.

Bump the workspace version 21.11.0 -> 21.12.0 (minor carries the
breaking change under the workspace release convention) and sync
the workspace.dependencies path versions via crate sync.
@ghfind-review ghfind-review Bot added the review: high ghfind author score; see https://ghfind.com label Oct 9, 2026
vshengbro added a commit to hyperlane-dev/hyperlane-quick-start that referenced this pull request Oct 9, 2026
hyperlane-core 21.12.0 changes Server::route to take
path: impl AsRef<str>; this branch registers routes through the
#[route] attribute macro (inventory-based), which never calls
Server::route, so no call sites change here.

The same release reduces several http-constant header-name
constants to pub(crate) visibility (rust-standards section 18):
ACCEPT_RANGES, AUTHORIZATION, CACHE_CONTROL, CONTENT_DISPOSITION,
CONTENT_RANGE, DATE, EXPIRES and RANGE were consumed across the
application crate's controllers, views, services and middleware.
They now live as one local copy in application/const.rs per the
section 18 consumer guidance, re-exported crate-internally from
application/lib.rs.

Cargo.lock intentionally still pins 21.10.0: crates.io serves
21.12.0 only after hyperlane-dev/hyperlane#43 merges and the
publish workflow runs. Run cargo update -p hyperlane after that to
refresh the lockfile.
vshengbro added a commit to hyperlane-dev/hyperlane-quick-start that referenced this pull request Oct 9, 2026
hyperlane-core 21.12.0 changes Server::route to take
path: impl AsRef<str>; this branch registers routes through the
#[route] attribute macro (inventory-based), which never calls
Server::route, so no call sites change here.

The same release reduces several http-constant header-name
constants to pub(crate) visibility (rust-standards section 18):
ACCEPT_RANGES, AUTHORIZATION, CACHE_CONTROL, CONTENT_DISPOSITION,
CONTENT_RANGE, DATE, EXPIRES and RANGE were consumed across the
application crate's controllers, views, services and middleware.
They now live as one local copy in application/header/const.rs per the
section 18 consumer guidance, re-exported crate-internally from
application/lib.rs.

Cargo.lock intentionally still pins 21.10.0: crates.io serves
21.12.0 only after hyperlane-dev/hyperlane#43 merges and the
publish workflow runs. Run cargo update -p hyperlane after that to
refresh the lockfile.
@vshengbro
vshengbro merged commit 4f43d39 into master Oct 9, 2026
8 checks passed
@vshengbro
vshengbro deleted the feat/server-route-infer-path-2026-10-09 branch October 9, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: high ghfind author score; see https://ghfind.com

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant