Add HasMessageView: link owned messages to their generated view types#158
Merged
Conversation
For each message Foo (when views are generated), generated code now implements buffa::HasMessageView, naming the borrowed view (Foo::View<'a> = FooView<'a>) and the 'static handle (Foo::ViewHandle = FooOwnedView), with provided decode_view_handle helpers. The generated FooOwnedView wrapper additionally implements AsRef<OwnedView<FooView<'static>>> so generic code can reach reborrow(), bytes(), and to_owned_message() through the handle without naming concrete types. This gives downstream frameworks a way to be generic over an owned message and work with its view types — decode a request body into a borrowed view, hold owned handles as stream items — without emitting per-message glue of their own. Code that reborrows generically adds M::View<'static>: ViewReborrow at the use site (a trait-level where clause currently trips a GAT normalization error).
|
All contributors have signed the CLA ✍️ ✅ |
rpb-ant
approved these changes
May 28, 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.
Summary
Adds
buffa::HasMessageView, a small trait that links an owned message type to its generated zero-copy view types, completing the wrapper surface introduced in #154:For each message
Foo(when views are generated), codegen emitsimpl HasMessageView for FoowithView<'a> = FooView<'a>andViewHandle = FooOwnedView, and the generatedFooOwnedViewwrapper additionally implementsAsRef<OwnedView<FooView<'static>>>. Together these let code that is generic over an owned message decode a request body intoM::View<'_>, holdM::ViewHandleitems, and reachreborrow()/bytes()/to_owned_message()through the handle — without per-message glue on the consumer's side. This is the hook an RPC framework needs to acceptMand work with its view types generically; it has been validated end-to-end against a connect-rust prototype, where it replaces an equivalent local shim.Example
The provided
decode_view_handle(concretely or asM::decode_view_handlein generic code) goes straight from wire bytes to the message's owned-view handle, where field access reads much like the pre-#154view.name— accessor methods instead ofDereffields, with every borrow tied to the handle:The difference from the pre-#154 ergonomics is deliberate: the borrow checker now enforces that field borrows stay within the handle's lifetime instead of letting them escape as
'static.Notes
M::View<'static>: ViewReborrowat the use site — a trait-levelwhereclause for it currently trips a GAT normalization error (documented on the trait).Testing
view_familymodule: a function generic overM: HasMessageViewexercising decode → AsRef → reborrow → bytes → owned round-trip (flat message and oneof), plus associated-type and Send/Sync assertions.task lint, full workspace tests (all features),check-nostd, and rustdoc link checks all pass.