From: Dirk Behme <dirk.behme@de.bosch.com>
To: <rust-for-linux@vger.kernel.org>
Cc: <dirk.behme@de.bosch.com>, <ojeda@kernel.org>,
<aliceryhl@google.com>, <daniel.almeida@collabora.com>,
<gary@garyguo.net>, <boqun.feng@gmail.com>
Subject: [RFC PATCH] rust: types: extend `Opaque` documentation
Date: Wed, 22 Jan 2025 06:53:47 +0100 [thread overview]
Message-ID: <20250122055347.597798-1-dirk.behme@de.bosch.com> (raw)
In the discussion linked below some `Opaque` documentation
updates have been proposed. Add them.
Suggested-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://lore.kernel.org/rust-for-linux/F8AB1160-F8CF-412F-8B88-4C79D65B53A1@collabora.com/
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
---
This is marked as RFC as it mainly takes some statements from
the linked discussion. Let us take this as a starting point
to discuss how we want to extend the `Opaque` documentation.
In that discussion it was mentioned
"Because `Opaque` implies the value may not be initialized,
it's similar to `MaybeUninit`."
I wonder if we want to add some explanation for the *difference*
between `Opaque` and `MaybeUninit`?
---
rust/kernel/types.rs | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index 994e504ca9075..a2d78a39a9b14 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -244,6 +244,13 @@ fn drop(&mut self) {
/// Using `Opaque<T>` allows to continue to use references on the Rust side even for values shared
/// with C.
///
+/// An `Opaque<T>` means that "this is a blob of bytes and don't touch it". It *might* or
+/// *might not* contain a valid `T`. By dereferencing a raw pointer to the inner value, you
+/// are unsafely asserting that it does in fact contain a valid `T` *right now*. As `T` can
+/// be uninitialized, no meaningful action can be performed when `T` is dropped. This means
+/// the destructor of `Opaque<T>` does *not* run the destructor of `T` as that can't work
+/// on potentially invalid `T` data.
+///
/// # Examples
///
/// ```
--
2.48.0
next reply other threads:[~2025-01-22 5:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 5:53 Dirk Behme [this message]
2025-01-22 9:41 ` [RFC PATCH] rust: types: extend `Opaque` documentation Miguel Ojeda
2025-01-23 9:39 ` Dirk Behme
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=20250122055347.597798-1-dirk.behme@de.bosch.com \
--to=dirk.behme@de.bosch.com \
--cc=aliceryhl@google.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/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