Borrowed request views: ServiceRequest and StreamMessage on buffa 0.7.0#143
Draft
iainmcgin wants to merge 3 commits into
Draft
Borrowed request views: ServiceRequest and StreamMessage on buffa 0.7.0#143iainmcgin wants to merge 3 commits into
iainmcgin wants to merge 3 commits into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
…n buffa 0.7.0 Unary and server-streaming handlers now take ServiceRequest<'_, Req>, a borrowed request wrapper that Derefs to the request view for field access and offers to_owned_message() (zero-copy from the retained body bytes), bytes(), and view(). Client-streaming and bidi inbound items become StreamMessage<M>, which Derefs to the buffa-generated FooOwnedView wrapper for per-field accessors and re-encodes from the retained wire bytes when forwarded. On the client, UnaryResponse::view() returns the reborrowed view and raw_bytes() is renamed to bytes(). Generated service traits and dispatchers adopt the new signatures. The view-family impls (HasMessageView, owned-view wrappers) now come from buffa 0.7.0's generated code instead of connect-codegen; inputs from extern_path crates fall back to &FooView<'_> parameters. The workspace requires buffa/buffa-types/buffa-codegen 0.7 and the checked-in generated code is regenerated with the 0.7.0 toolchain. Not yet ported to the new signatures: the conformance server, the examples, the rpc benches, and the guide/README handler examples.
47aac9a to
a2e1b52
Compare
…ionally Drop the borrowed-view fallback for request parameters and inbound stream items whose types resolve through extern_path. The fallback existed because connect could not know whether the foreign crate's generated code provides buffa::HasMessageView; that is now a documented requirement instead: every extern_path target must be buffa >= 0.7.0 generated code with views enabled, the same way the stubs already rely on the JSON serialization impls. buffa-types 0.7+ satisfies this for the well-known types, and a non-conforming crate fails to compile with a missing HasMessageView impl. All Router, Dispatcher, and trait-method emission sites now produce the same ServiceRequest<'_, Req> / StreamMessage<Req> surface regardless of where the input type lives. The now-dead owned_view_input_arg_type helper and unused BatchState parameters are removed, and the requirement is documented in the Options rustdoc, the plugin option docs, the README, and the generated trait docs. The output-side rule is unchanged: Encodable view-body impls are still not emitted for extern output types (those would be orphan impls in the consumer crate).
connyay
added a commit
to connyay/connectrpc-workers
that referenced
this pull request
Jun 2, 2026
This reverts commit 7bfdba7. Needs anthropics/connect-rust#143
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Reworks the server-side request surface around buffa 0.7.0, which removes the
OwnedViewDerefimpl (which let safe code hold view fields past the backing buffer's lifetime) and introducesHasMessageViewplus generatedFooOwnedViewaccessor wrappers. Rather than just absorbing the ergonomic loss, handlers move to a new request/stream-item API:ServiceRequest<'a, Req>— unary and server-streaming handlers now take a borrowed request (req: ServiceRequest<'_, GreetRequest>). It Derefs to the request view for field access, and offersto_owned_message()(zero-copy via the retained body bytes),bytes(), andview(). Borrowing across.awaitworks; moving intotokio::spawnrequiresto_owned_message()(enforced by the compiler).StreamMessage<M>— client-streaming and bidi inbound items. Derefs to the buffa-generatedFooOwnedViewwrapper for per-field accessors, and re-encodes from the retained wire bytes when forwarded.UnaryResponse::view()returns the reborrowed view;raw_bytes()is renamed tobytes().buffa/buffa-types/buffa-codegen0.7; checked-in generated code is regenerated with the 0.7.0 toolchain.extern_pathtypes use the same wrappers (second commit). The earlier borrowed-view fallback for inputs mapped viaextern_pathis gone; instead the requirement is documented (README, plugin option docs,Optionsrustdoc, generated trait docs): everyextern_pathtarget must be buffa ≥ 0.7.0 generated code with views enabled, the same way the stubs already rely on the JSON impls. buffa-types 0.7+ satisfies this for well-known types; a non-conforming crate fails to compile on the missingHasMessageViewimpl, and anthropics/buffa#161 adds a#[diagnostic::on_unimplemented]note to that trait so the error explains the fix. The output side is unchanged:Encodableview-body impls are still per-type and skipped for extern outputs (a blanket impl keyed through theHasMessageViewGAT was tried and is not coherent next to theM: Message + Serializeblanket).Status — not yet complete
connectrpc,connectrpc-codegen,connectrpc-build, and thetests/streaminge2e suite build and pass against published buffa 0.7.0; clippy and rustfmt clean.conformance,examples/*(eliza, multiservice, middleware, mtls-identity, streaming-tour), andbenches/rpcstill implement the oldOwnedView<...>handler signatures, so workspace-wide clippy/test CI will be red until they are updated.Heartbeat(google.protobuf.Empty) → Timestamp-style RPC in the multiservice WKT example, so the extern-input/output paths are compiled in CI rather than only asserted in codegen unit tests.docs/guide.mdand the README handler examples still show the old signatures.Opening as a draft so the API surface can be reviewed holistically ahead of a connect-rust 0.7.0 release alongside buffa 0.7.0.