Repository navigation
spec: add Spec, StreamType, IdempotencyLevel; thread through dispatch - #112
Merged
iainmcgin merged 4 commits intoMay 19, 2026
Merged
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
This was referenced May 18, 2026
Add static per-method metadata that handlers (and a future interceptor surface) can read without re-parsing the request URL. - New `connectrpc::spec` module: `Spec` (procedure path, stream type, idempotency, client/server side), `StreamType`, `IdempotencyLevel`. All `Copy` and `'static`, with `const fn` builders so codegen can emit `Spec` constants in `.rodata`. - `MethodDescriptor` gains `spec: Option<Spec>`, becomes `#[non_exhaustive]`, and grows `from_kind`/`with_idempotent`/`with_spec` const builders. The dynamic `Router` returns `spec: None` (its keys are owned `String`s, not `&'static str`). - `RequestContext` gains `spec: Option<Spec>` and `protocol: Option<Protocol>` with `with_spec`/`with_protocol` builders. - The dispatch path in `service.rs` threads the looked-up `Spec` and the negotiated `Protocol` into every `RequestContext` (Connect unary, gRPC unary fast path, server/client/bidi streaming). - `connectrpc-codegen` emits a `pub const FOO_SERVICE_BAR_SPEC: Spec` per method and references it from the generated `Dispatcher::lookup`. `Protocol` lives on `RequestContext` rather than `Spec` because it is connection-scoped, not method-scoped (matching connect-go's `Spec`/`Peer` split); a `const Spec` cannot carry a runtime-negotiated field. Conformance: 3600/3600 (no behavioral change to wire handling).
aknott-ant
force-pushed
the
aknott/interceptors-pr1-spec
branch
from
May 18, 2026 18:33
873a3c6 to
ab3f73d
Compare
Collaborator
|
recheck |
1 similar comment
Collaborator
|
recheck |
Collaborator
Author
|
I have read the CLA Document and I hereby sign the CLA |
Review follow-ups for the Spec/RequestContext metadata PR. - Replace `is_client: bool` with `origin: SpecOrigin` and side-specific constructors `Spec::server(...)` / `Spec::client(...)` (replacing `Spec::new(...)`). Closed two-valued domains read better as an enum than a bool: `spec.origin == SpecOrigin::Client` over `spec.is_client`, and codegen picks the side at the constructor call rather than via a builder. The `Spec` prefix on the type name keeps it distinct from a request "origin" in the HTTP/CORS sense. - Rename `idempotency` -> `idempotency_level` (and `with_idempotency` -> `with_idempotency_level`) so the field name matches both the sibling `stream_type: StreamType` pattern and the proto option name (`idempotency_level`); also matches connect-go's `IdempotencyLevel`. - Add a `const fn` debug assertion in `Spec::server` / `Spec::client` that the procedure path starts with `/` and contains a `/Service/Method` separator. A malformed path in a const SPEC is now a debug-build compile error instead of a silently misleading `service()` / `method()` accessor result. - Add unit tests for `RequestContext::with_spec` / `with_protocol` round-trip and `MethodDescriptor::from_kind` / `with_idempotent` / `with_spec` const builder chain. - Add CHANGELOG `[Unreleased]` entries for the new `spec` module under `### Added` and the `MethodDescriptor` `#[non_exhaustive]` change under `### Breaking`. - Add a "Static method metadata (`Spec`)" subsection to docs/guide.md under Tower middleware: how to read `ctx.spec()`, the `Router` returns-`None` gotcha, the generated `<SERVICE>_<METHOD>_SPEC` constants, and the `connect-go` `Spec`/`Peer` split. - Regenerate all checked-in `*.__connect.rs` for the renamed builders. Refs connectrpc#87, connectrpc#110.
…r test clippy::assertions_on_constants flags `assert!(!DESC.idempotent)` when DESC is a `const`. Bind it as a `let` for the runtime assertions and keep a separate `const _: MethodDescriptor = ...` to verify the builder chain is `const`-evaluable.
iainmcgin
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add static per-method metadata that handlers (and a future interceptor surface) can read without re-parsing the request URL.
connectrpc::specmodule:Spec(procedure path, stream type, idempotency level, client/server side),StreamType,IdempotencyLevel,SpecOrigin. AllCopyand'static, withconst fnconstructors (Spec::server(...)/Spec::client(...)) so codegen can emitSpecconstants in.rodata.MethodDescriptorgainsspec: Option<Spec>, becomes#[non_exhaustive], and growsfrom_kind/with_idempotent/with_specconst builders. The dynamicRouterreturnsspec: None(its keys are ownedStrings, not&'static str).RequestContextgainsspec: Option<Spec>andprotocol: Option<Protocol>withwith_spec/with_protocolbuilders.service.rsthreads the looked-upSpecand the negotiatedProtocolinto everyRequestContext(Connect unary, gRPC unary fast path, server/client/bidi streaming).connectrpc-codegenemits apub const FOO_SERVICE_BAR_SPEC: Specper method and references it from the generatedDispatcher::lookup.[Unreleased]entries and adocs/guide.md"Static method metadata (Spec)" subsection coveringctx.spec(), theRouter-returns-Nonegotcha, and the generated<SERVICE>_<METHOD>_SPECconstants.Protocollives onRequestContextrather thanSpecbecause it is connection-scoped, not method-scoped (matching connect-go'sSpec/Peersplit); aconst Speccannot carry a runtime-negotiated field.SpecOriginis an enum (Server/Client) rather than connect-go'sIsClient bool— closed two-valued domains read better as enums in Rust (spec.origin == SpecOrigin::Client), the constructorsSpec::server(...)/Spec::client(...)carry the side at the call site without a builder, and theSpecprefix disambiguates from a request "origin" in the HTTP/CORS sense.Conformance: 3600/3600 (no behavioral change to wire handling).
Refs #87, #110.