[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z8mPBvL--zUxBpYN@mango>
Date: Thu, 06 Mar 2025 12:03:23 +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 1131, Alice Ryhl wrote:
>
> How about this:
>
> * Rename AlwaysRefCounted to RefCounted.
> * Introduce a new AlwaysRefCounted trait with no methods and gate
> `From<&T>` on it. It has RefCounted as a sub-trait.
> * Introduce an Ownable trait with an Owned type like in [1].
> * Given an Owned<T> where T:RefCounted you can convert from Owned<T> to
> ARef<T>.
>
> And there needs to be a safety requirement on Ownable or
> AlwaysRefCounted which requires that a type cannot implement both
> traits. Alternatively, if a type implements both, it needs to be safe to
> have both Owned<T> and ARef<T> references at the same time, which could
> make sense for a type that has one "special" reference and many normal
> references.
>
> If you want conversions ARef<T> to Owned<T>, you should add a new trait
> TryIntoOwned that's a super-trait of both RefCounted and Owned and has
> the `try` method for the conversion.
>
> Thoughts?
>
Yes. Sounds good to me. Basically what I had in mind. Only the naming
is different.
I will build an implementation like this and post it as v5.
I won't change the names of UniqueRef and UniqueRefCounted for now,
but more out of laziness than because of having strong feelings about it.
I like UniqueRef a bit better as our focus is on pointing out that
it is unique. But if you or other prefers Owned I can change it.
>
> [1]: https://lore.kernel.org/rust-for-linux/20250202-rust-page-v1-1-e3170d7fe55e@asahilina.net/
Oh, really very similar.
Powered by blists - more mailing lists