Skip to content

feat: refine macros for comprehensive member accessor codegen - #362

Draft
cartercanedy wants to merge 22 commits into
HMIProject:mainfrom
cartercanedy:cc/member-accessor-impls
Draft

cartercanedy wants to merge 22 commits into
HMIProject:mainfrom
cartercanedy:cc/member-accessor-impls

Conversation

@cartercanedy

Copy link
Copy Markdown
Contributor

open62541 holds a pretty high bar with respect to symbol naming consistency, which enables generalizable macros for scaffolding out accessors for each types members.

Summary

  • break up data_type! macro into 2 macros:

    • data_type_baseline!:
      the minimal set of trait impls that both stack-bound and pointer-holding types implement via deference to native open62541 impls (e.g. Hash, PartialEq/Eq, etc.) that doesn't impose a default Drop implementation.

      This enables usage of otherwise const-compatible wrapper types (i.e. completely stack-bound primitive type wrappers) in const contexts, and allows use of auto-derived Clone/Copy implementations (again, useful in const contexts).

    • data_type!:
      The semantics of this macro didn't change, it simply expands data_type_baseline! before implementing Clone & Drop as redirections to UA_copy & UA_clear.

    Soundness is maintained by compiler enforcement, since open62541-sys's bindgen turns off auto-derivation of Clone/Copy for struct declarations but emits typedefs of primitives as native pub type UA_<T> = <rust-primitive-dtype> declarations. This still restricts types that may or may not be Copy-safe, but allows for enums & trivially copyable numerics to pass through.

  • member_accessors! macro:

    • struct-like member declaration syntax that relies on statically-verifiable type relationships
    • immutable (and optionally mutable) scalar member access
    • array member
    • attribute-like syntax for declaring skipped implementations (e.g. accessors for *_timestamp on DataValue)
  • remove all manually-implemented member accessor implementations in favor of generated methods

Note:
I realize that this is a huge PR to review, so I totally understand if it takes a while. In the spirit of OSS, though, I'm opening this PR since we're relying on these patches downstream in the instro library, and I'm sure that other consumers of this crate could also benefit from these changes.

This is stacked on top of #349. Will rebase as the stack gets whittled down

@cartercanedy
cartercanedy force-pushed the cc/member-accessor-impls branch 2 times, most recently from 7af04fa to 9cb5f6a Compare October 22, 2026 03:58
@cartercanedy
cartercanedy force-pushed the cc/member-accessor-impls branch from f156c74 to 98da2de Compare October 23, 2026 19:23
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.

1 participant