From: Igor Korotin <igor.korotin.linux@gmail.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
rust-for-linux@vger.kernel.org
Subject: Rust: Manual reimplementation of C unions and layout testing
Date: Tue, 21 Oct 2025 22:02:52 +0100 [thread overview]
Message-ID: <af7a8880-e166-4e1a-851d-31b731c2d2fa@gmail.com> (raw)
Hello all,
As you might know, I'm working on the Rust side of the I2C subsystem,
and currently looking into representing `struct i2c_algorithm`.
In C, this struct contains two anonymous unions for callbacks.
bindgen generates rather awkward names for them, which makes the Rust
bindings less readable and less stable.
I'm considering declaring this structure manually in i2c.rs, effectively
copying the layout that bindgen would generate but renaming the union
fields for clarity. To avoid accidental ABI drift, I could add
compile-time assertions to ensure the Rust and C layouts remain compatible.
Would that be an acceptable approach?
Any thoughts or preferences on how such layout checks should be done
in-tree?
Best regards,
Igor Korotin
next reply other threads:[~2025-10-21 21:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-21 21:02 Igor Korotin [this message]
2025-10-21 21:22 ` Rust: Manual reimplementation of C unions and layout testing Matthew Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=af7a8880-e166-4e1a-851d-31b731c2d2fa@gmail.com \
--to=igor.korotin.linux@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).