Add type_attribute, field_attribute, and message_attribute support#44
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
- Extend type_attribute / field_attribute coverage to oneof enums and their variants via the oneof's fully-qualified proto path (e.g. .pkg.Msg.my_oneof and .pkg.Msg.my_oneof.variant_a). - Return a CodeGenError::InvalidCustomAttribute when an attribute string fails to parse, instead of silently emitting a doc-comment fallback that could go unnoticed in CI. - Demote CodeGenContext::matching_attributes from pub to pub(crate) — it is a codegen-internal helper. - Extract a shared matches_proto_prefix helper so use_bytes_type gets the same proto-segment-aware matching (previously a plain starts_with matched '.my.pk' against '.my.pkg.Msg.data'). - Normalize user-supplied attribute paths: trim trailing dots and keep the bare catch-all '.' intact. - Document the duplicate-derive pitfall and oneof coverage in the buffa-build rustdoc; add build-layer tests for normalization and codegen-layer tests for oneof coverage + the parse-error path.
Mark the legacy Person.address.freeform_address oneof variant as #[deprecated] via buffa-build's new field_attribute hook, and update the addressbook CLI to stop offering it on new writes while still reading existing records that contain it. This is the canonical deprecation-migration pattern and exercises the oneof-variant path of the custom-attributes support end-to-end. The write path now only creates structured_address entries; the read path uses a scoped #[allow(deprecated)] so warnings still fire on any accidental writes elsewhere. The generated module is wrapped in #[allow(deprecated)] because codegen's own encode/decode paths match on every variant regardless of deprecation.
iainmcgin
left a comment
There was a problem hiding this comment.
Approved. All review findings addressed in the maintainer-side fix-up; example demonstrates the feature end-to-end; 7/7 CI green.
|
[claude code] Thanks for this, @jlucaso1 — A summary of the changes I made on top of your branch before merging, in case you're curious about the follow-up work: Visibility and error hygiene
Oneof coverage Wired
Previously both silently no-op'd, which would have been a surprising regression from prost for anyone migrating. Matcher hardening
Tests and docs
Example Added a demo in Also worth flagging a semi-related change that landed between your PR's original push and this merge: #34 switched oneof enums to a uniform Thanks again! |
Adds prost-compatible
type_attribute(),field_attribute(), andmessage_attribute()builder methods tobuffa_build::Config, allowing custom attributes on generated types, fields, and message structs.This is the main missing piece for migrating from prost when projects rely on custom derives or per-field serde attributes (feature-gated derives,
#[serde(skip)]on specific fields, struct-only#[serde(default)], etc.).Changes
buffa-codegenlib.rsVec<(String, String)>fields onCodeGenConfigbuffa-codegencontext.rsmatching_attributes()— prefix-matches FQN, parses intoTokenStreambuffa-codegenmessage.rsbuffa-codegenenumeration.rsbuffa-buildlib.rsPath matching follows the same convention as prost:
"."matches everything,".my.pkg"matches a package prefix,".my.pkg.MyMessage"matches a specific type. Partial segment matches are rejected (.my.pkdoes not match.my.pkg).Follow-up
enum_attribute()(enum-only counterpart tomessage_attribute()) could be added in a separate PR if there's demand.Closes #43