[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z8l1Zt3ibanzBhnX@mango>
Date: Thu, 06 Mar 2025 10:14:05 +0000
From: Oliver Mangold <oliver.mangold@...me>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Andreas Hindborg <a.hindborg@...nel.org>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>, Trevor Gross <tmgross@...ch.edu>, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4] rust: adding UniqueRefCounted and UniqueRef types
On 250306 0935, Alice Ryhl wrote:
>
> Ultimately, if a struct implements AlwaysRefcounted, then you can always
> increments its refcount.
> If you want a version of the struct where that
> is not the case, then you need a different struct that does *not*
> implement AlwaysRefcounted.
>
I guess so, but it would be possible to make 'From<&T> for ARef<T>' opt-in,
by requiring a separate marker trait.
That you can call 'AlwaysRefCounted::inc_ref()' directly doesn't seem a
problem to me, as it will only leak the object, not create a reference.
A quick grep shows me that there are currently 7 implementers:
unsafe impl AlwaysRefCounted for Credential {
unsafe impl AlwaysRefCounted for File {
unsafe impl AlwaysRefCounted for LocalFile {
unsafe impl<T: Operations> AlwaysRefCounted for Request<T> {
unsafe impl crate::types::AlwaysRefCounted for Device {
unsafe impl crate::types::AlwaysRefCounted for Task {
unsafe impl AlwaysRefCounted for PidNamespace {
So it looks doable to me.
Oliver
Powered by blists - more mailing lists