From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Oliver Mangold" <oliver.mangold@pm.me>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2] rust: adding UniqueRefCounted and UniqueRef types
Date: Mon, 03 Mar 2025 15:09:59 +0100 [thread overview]
Message-ID: <87zfi2jjd4.fsf@kernel.org> (raw)
In-Reply-To: <Z8H6EUy1HqLrzytE@laptop> (Oliver Mangold's message of "Fri, 28 Feb 2025 18:01:55 +0000")
"Oliver Mangold" <oliver.mangold@pm.me> writes:
[...]
> +/// Types that are [`AlwaysRefCounted`] and can be safely converted to an [`UniqueRef`]
> +///
> +/// # Safety
> +///
> +/// Implementers must ensure that the methods of the trait
> +/// change the reference count of the underlying object such that:
> +/// - the uniqueness invariant is upheld, i.e. it is not possible
> +/// to obtain another reference by any means (other than through the [`UniqueRef`])
> +/// until the [`UniqueRef`] is dropped or converted to an [`ARef`].
> +/// - [`UniqueRefCounted::dec_ref`] correctly frees the underlying object.
> +/// - [`UniqueRefCounted::unique_to_shared`] set the reference count to the value
> +/// - that the returned [`ARef`] expects for an object with a single reference
> +/// in existence.
> +pub unsafe trait UniqueRefCounted: AlwaysRefCounted + Sized {
> + /// Checks if the [`ARef`] is unique and convert it
> + /// to an [`UniqueRef`] it that is that case.
> + /// Otherwise it returns again an [`ARef`] to the same
> + /// underlying object.
> + fn try_shared_to_unique(this: ARef<Self>) -> Result<UniqueRef<Self>, ARef<Self>>;
This could just be `try_into_unique`, since the type of `this` gives the
rest of the context.
> + /// Converts the [`UniqueRef`] into an [`ARef`].
> + fn unique_to_shared(this: UniqueRef<Self>) -> ARef<Self>;
Similarly, this could be `into_shared`.
Best regards,
Andreas Hindborg
next prev parent reply other threads:[~2025-03-03 14:10 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 14:43 [PATCH] rust: adding UniqueRefCounted and UniqueRef types Oliver Mangold
2025-02-28 15:21 ` Miguel Ojeda
2025-02-28 15:54 ` Boqun Feng
2025-02-28 18:01 ` [PATCH v2] " Oliver Mangold
2025-02-28 18:09 ` Boqun Feng
2025-02-28 18:16 ` Boqun Feng
2025-02-28 18:29 ` Andreas Hindborg
2025-03-03 13:29 ` [PATCH v3] " Oliver Mangold
2025-03-03 14:22 ` Andreas Hindborg
2025-03-03 16:33 ` Oliver Mangold
2025-03-03 14:09 ` Andreas Hindborg [this message]
2025-02-28 23:41 ` [PATCH] " Benoît du Garreau
2025-03-01 8:06 ` Oliver Mangold
-- strict thread matches above, loose matches on Subject: below --
2025-02-28 18:22 [PATCH v2] " Oliver Mangold
2025-02-28 18:33 ` Boqun Feng
2025-02-28 19:01 ` Andreas Hindborg
2025-02-28 19:06 ` Boqun Feng
2025-02-28 19:16 ` Oliver Mangold
2025-02-28 19:25 ` Andreas Hindborg
2025-02-28 19:47 ` Oliver Mangold
2025-02-28 20:07 ` Oliver Mangold
2025-02-28 18:41 Oliver Mangold
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=87zfi2jjd4.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=oliver.mangold@pm.me \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.