Skip to content

docs: surface MessageField/EnumValue From conveniences and derive guidance#306

Merged
iainmcgin merged 2 commits into
anthropics:mainfrom
Yong-yuan-X:docs/issue-249-conversion-and-derive-docs
Jul 16, 2026
Merged

docs: surface MessageField/EnumValue From conveniences and derive guidance#306
iainmcgin merged 2 commits into
anthropics:mainfrom
Yong-yuan-X:docs/issue-249-conversion-and-derive-docs

Conversation

@Yong-yuan-X

Copy link
Copy Markdown
Contributor

Summary

  • Add type-level rustdoc examples showing idiomatic .into() construction and direct unwrap() usage for MessageField.
  • Add type-level rustdoc examples showing .into() conversions for known and unknown EnumValue values.
  • Update the guide and prost migration examples to use the documented conversion conveniences.
  • Explain why production message types are generated from .proto files and link to buffa-test-fixtures: minimal #[derive(Message)] for tests and doc examples #226 for the proposed test-fixture derive.
  • Add a changelog fragment for the documentation improvements.

This is a documentation-only change with no API or codegen changes.

Testing

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo rustdoc -p buffa --all-features -- -D warnings
  • npx.cmd --yes markdownlint-cli@0.47.0 docs/guide.md docs/migration-from-prost.md
  • cargo test -p buffa --doc MessageField
  • cargo test -p buffa --doc EnumValue

Closes #249

@github-actions

Copy link
Copy Markdown

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

The MessageField example built a local type with no DefaultInstance impl, so
the only way to read the value back was unwrap() — teaching a panic on the one
type whose purpose is to avoid it. Use the Person fixture instead and read
through Deref, which is the path the type exists to offer.

Both new examples were marked no_run, so their assertions were compiled but
never executed. Drop it: they are self-contained and now actually check what
they claim.

Move "Where is #[derive(Message)]?" out of the middle of Quick start, where it
had orphaned the DecodeOptions guidance under a heading about derive macros,
and drop the paragraph citing an open issue for an unbuilt crate — rustdoc is
snapshotted per release, so that text would outlive whatever anthropics#226 becomes. The
prost guide keeps a live tracking link, which is the right home for it.

Give the protobuf migration guide the same derive answer as the prost one, and
hide the enum example's scaffolding behind # lines.

No-Verification-Needed: docs and doc comments only; doctests run in CI

@iainmcgin iainmcgin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude code] Thanks for this — #249 asked for exactly these two things (surface the .into() conveniences, answer "where's the derive?"), and the conversions you documented are the right ones: I checked each From impl the examples lean on and they all exist with the shown signatures.

I pushed one commit (8db91ab) rather than sending it back to you. Four things, two of which are worth explaining:

The MessageField example was teaching a panic. The local Address type in it has no DefaultInstance impl, which means Deref — the whole reason MessageField exists, and the thing the guide sells two sections earlier as "eliminating unwrap ceremony" — isn't available on it, so the only way to read the value back was field.unwrap(). The example therefore showcased the panicking path on the type designed to avoid it, and doc examples get copied into production code. It now uses the Person doctest fixture and reads through deref (field.name), including the unset case derefing to the default instance instead of panicking.

Both examples were no_run, so every assert_eq! in them was decorative — compiled, never executed. Dropped it on both; they're self-contained and pass. They now genuinely guard the behavior they document (message_field.rs line 286 and enumeration.rs line 66 both run under cargo test --doc).

The other two: the # Where is #[derive(Message)]? heading had landed in the middle of # Quick start, so on docs.rs the DecodeOptions example and the recursion/unknown-field-limit paragraph rendered underneath a heading asking about derive macros — moved it below Quick start. And I dropped the paragraph citing #226 for buffa-test-fixtures from lib.rs: rustdoc is snapshotted per release, so "issue #226 proposes X, it is not currently available" freezes into every future version's docs the day #226 is closed or changes shape. The prost migration guide keeps a live tracking link, which is the right home for it since repo docs track main. While there I gave migration-from-protobuf.md the same derive answer as the prost guide (it still said "Implement Message by hand"), and hid the enum example's impl Enumeration scaffolding behind # lines so the four .into() lines that matter are what a reader sees.

Gates on the merged branch: cargo fmt --check, RUSTDOCFLAGS='-D warnings' cargo doc --all-features (this one caught a redundant link target in my own edit), and cargo test -p buffa --doc (15 pass) all clean.

Approving — thank you for picking this up, and for a genuinely accurate set of examples.

@iainmcgin
iainmcgin enabled auto-merge July 16, 2026 18:34
@iainmcgin
iainmcgin added this pull request to the merge queue Jul 16, 2026
Merged via the queue into anthropics:main with commit 8d36843 Jul 16, 2026
9 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: surface MessageField/EnumValue From conveniences; add "where's #[derive]?" pointer

2 participants