Skip to content

types: add the Any type-URL helpers to AnyView - #734

Open
farmer-data wants to merge 2 commits into
anthropics:mainfrom
farmer-data:feat/anyview-type-url-helpers-643
Open

farmer-data wants to merge 2 commits into
anthropics:mainfrom
farmer-data:feat/anyview-type-url-helpers-643

Conversation

@farmer-data

Copy link
Copy Markdown
Contributor

Fixes #643.

AnyView gains inherent type_name, is_message, is_type, unpack_message and unpack_if, so a zero-copy handler can test and unpack the packed type without converting to an Any or splitting type_url by hand.

  • Any::type_name and AnyView::type_name now share one private type_name_of, so the rules can't drift, including the bare-name reading from any: read a type URL without a '/' as a bare message name #692. AnyView::type_name returns Option<&'a str>, borrowing from the decoded buffer rather than the view.
  • unpack_message and unpack_if decode an owned T from the borrowed value. For a view of the payload, the docs point to is_message::<FooView>() plus FooView::decode_view(view.value). A view-returning unpack_view would be additive, and I left it out since Any has no counterpart.
  • Tests: a table test checks every helper against Any on 8 type URLs (empty, trailing /, no /, a near-miss name, other prefixes), plus lifetime, view-type and decode-error tests. The guide's Any section gets one paragraph, including how to reach the helpers from AnyOwnedView via view().

Verification: task lint, task test-local (4293 passed, 0 failed) and strict task doc pass with the repo-pinned protoc 33.5. Reviewed with rust-code-reviewer and rust-api-ergonomics-reviewer per CLAUDE.md: no Critical or High findings. The Medium (the is_type doc wording) and the doc Lows are addressed.

@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Fixes anthropics#643.

AnyView gains inherent type_name, is_message, is_type, unpack_message and
unpack_if, sharing the type-name rule with Any through a private
type_name_of. AnyView::type_name returns Option<&'a str>, borrowing from
the decoded buffer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

types: AnyView has none of Any's type-URL helpers

1 participant