rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: types: remove `Either<L, R>`
@ 2025-05-19 12:43 Benno Lossin
  2025-05-19 17:14 ` Danilo Krummrich
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Benno Lossin @ 2025-05-19 12:43 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein, Dirk Behme,
	Kartik Prajapati, Aliet Exposito Garcia
  Cc: Benno Lossin, rust-for-linux, linux-kernel

This enum is not used. Additionally, using it would result in poor
ergonomics, because in order to do any operation on a value it has to be
matched first. Our version of `Either` also doesn't provide any helper
methods making it even more difficult to use.

The alternative of creating a custom enum for the concrete use-case also
is much better for ergonomics. As one can provide functions on the type
directly and users don't need to match the value manually.

Signed-off-by: Benno Lossin <lossin@kernel.org>
---
 rust/kernel/types.rs | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index 86562e738eac..8830f8c2d12e 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -556,24 +556,6 @@ fn drop(&mut self) {
     }
 }
 
-/// A sum type that always holds either a value of type `L` or `R`.
-///
-/// # Examples
-///
-/// ```
-/// use kernel::types::Either;
-///
-/// let left_value: Either<i32, &str> = Either::Left(7);
-/// let right_value: Either<i32, &str> = Either::Right("right value");
-/// ```
-pub enum Either<L, R> {
-    /// Constructs an instance of [`Either`] containing a value of type `L`.
-    Left(L),
-
-    /// Constructs an instance of [`Either`] containing a value of type `R`.
-    Right(R),
-}
-
 /// Zero-sized type to mark types not [`Send`].
 ///
 /// Add this type as a field to your struct if your type should not be sent to a different task.

base-commit: 22c3335c5dcd33063fe1894676a3a6ff1008d506
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] rust: types: remove `Either<L, R>`
  2025-05-19 12:43 [PATCH] rust: types: remove `Either<L, R>` Benno Lossin
@ 2025-05-19 17:14 ` Danilo Krummrich
  2025-05-19 17:30 ` Alice Ryhl
  2025-07-21 21:59 ` Miguel Ojeda
  2 siblings, 0 replies; 8+ messages in thread
From: Danilo Krummrich @ 2025-05-19 17:14 UTC (permalink / raw)
  To: Benno Lossin
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Tamir Duberstein, Dirk Behme, Kartik Prajapati,
	Aliet Exposito Garcia, rust-for-linux, linux-kernel

On 5/19/25 2:43 PM, Benno Lossin wrote:
> This enum is not used. Additionally, using it would result in poor
> ergonomics, because in order to do any operation on a value it has to be
> matched first. Our version of `Either` also doesn't provide any helper
> methods making it even more difficult to use.
> 
> The alternative of creating a custom enum for the concrete use-case also
> is much better for ergonomics. As one can provide functions on the type
> directly and users don't need to match the value manually.
> 
> Signed-off-by: Benno Lossin <lossin@kernel.org>

Reviewed-by: Danilo Krummrich <dakr@kernel.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rust: types: remove `Either<L, R>`
  2025-05-19 12:43 [PATCH] rust: types: remove `Either<L, R>` Benno Lossin
  2025-05-19 17:14 ` Danilo Krummrich
@ 2025-05-19 17:30 ` Alice Ryhl
  2025-05-19 18:08   ` Miguel Ojeda
  2025-07-21 21:59 ` Miguel Ojeda
  2 siblings, 1 reply; 8+ messages in thread
From: Alice Ryhl @ 2025-05-19 17:30 UTC (permalink / raw)
  To: Benno Lossin
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein, Dirk Behme,
	Kartik Prajapati, Aliet Exposito Garcia, rust-for-linux,
	linux-kernel

On Mon, May 19, 2025 at 5:43 AM Benno Lossin <lossin@kernel.org> wrote:
>
> This enum is not used. Additionally, using it would result in poor
> ergonomics, because in order to do any operation on a value it has to be
> matched first. Our version of `Either` also doesn't provide any helper
> methods making it even more difficult to use.
>
> The alternative of creating a custom enum for the concrete use-case also
> is much better for ergonomics. As one can provide functions on the type
> directly and users don't need to match the value manually.
>
> Signed-off-by: Benno Lossin <lossin@kernel.org>

I don't mind making a custom enum, but I do use this in Rust Binder.

Alice

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rust: types: remove `Either<L, R>`
  2025-05-19 17:30 ` Alice Ryhl
@ 2025-05-19 18:08   ` Miguel Ojeda
  2025-05-19 18:12     ` Alice Ryhl
  2025-05-19 18:23     ` Benno Lossin
  0 siblings, 2 replies; 8+ messages in thread
From: Miguel Ojeda @ 2025-05-19 18:08 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Benno Lossin, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein, Dirk Behme,
	Kartik Prajapati, Aliet Exposito Garcia, rust-for-linux,
	linux-kernel

On Mon, May 19, 2025 at 7:30 PM Alice Ryhl <aliceryhl@google.com> wrote:
>
> I don't mind making a custom enum, but I do use this in Rust Binder.

Yeah, Wedson added the type back then for Binder and kasync from a
quick look -- in those times, I see it in a few places only, e.g. in
`get_work_or_register`. Do you have many nowadays?

i.e. I don't want to add extra work for upstreaming Rust Binder, so if
that would make it harder downstream, we can live with it for the
moment.

We may want to add a line in the docs to ask the potential user to
consider whether a custom enum would be better nevertheless.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rust: types: remove `Either<L, R>`
  2025-05-19 18:08   ` Miguel Ojeda
@ 2025-05-19 18:12     ` Alice Ryhl
  2025-05-19 18:23     ` Benno Lossin
  1 sibling, 0 replies; 8+ messages in thread
From: Alice Ryhl @ 2025-05-19 18:12 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Benno Lossin, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein, Dirk Behme,
	Kartik Prajapati, Aliet Exposito Garcia, rust-for-linux,
	linux-kernel

On Mon, May 19, 2025 at 11:08 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Mon, May 19, 2025 at 7:30 PM Alice Ryhl <aliceryhl@google.com> wrote:
> >
> > I don't mind making a custom enum, but I do use this in Rust Binder.
>
> Yeah, Wedson added the type back then for Binder and kasync from a
> quick look -- in those times, I see it in a few places only, e.g. in
> `get_work_or_register`. Do you have many nowadays?
>
> i.e. I don't want to add extra work for upstreaming Rust Binder, so if
> that would make it harder downstream, we can live with it for the
> moment.
>
> We may want to add a line in the docs to ask the potential user to
> consider whether a custom enum would be better nevertheless.

It's used get_work_or_register to return either work, or a
registration waiting for work if the work list is empty. I believe
there is only that one use.

Alice

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rust: types: remove `Either<L, R>`
  2025-05-19 18:08   ` Miguel Ojeda
  2025-05-19 18:12     ` Alice Ryhl
@ 2025-05-19 18:23     ` Benno Lossin
  2025-07-21 21:58       ` Miguel Ojeda
  1 sibling, 1 reply; 8+ messages in thread
From: Benno Lossin @ 2025-05-19 18:23 UTC (permalink / raw)
  To: Miguel Ojeda, Alice Ryhl
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein, Dirk Behme,
	Kartik Prajapati, Aliet Exposito Garcia, rust-for-linux,
	linux-kernel

On Mon May 19, 2025 at 8:08 PM CEST, Miguel Ojeda wrote:
> On Mon, May 19, 2025 at 7:30 PM Alice Ryhl <aliceryhl@google.com> wrote:
>>
>> I don't mind making a custom enum, but I do use this in Rust Binder.
>
> Yeah, Wedson added the type back then for Binder and kasync from a
> quick look -- in those times, I see it in a few places only, e.g. in
> `get_work_or_register`. Do you have many nowadays?
>
> i.e. I don't want to add extra work for upstreaming Rust Binder, so if
> that would make it harder downstream, we can live with it for the
> moment.

I can also take a look and make a patch that uses a custom enum instead
if you don't want to do that, Alice.

Another option would be to deprecate it. Do I remember correctly that
Linus doesn't like that? If yes, then that maybe isn't a good idea...

> We may want to add a line in the docs to ask the potential user to
> consider whether a custom enum would be better nevertheless.

Yeah that too.

---
Cheers,
Benno

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rust: types: remove `Either<L, R>`
  2025-05-19 18:23     ` Benno Lossin
@ 2025-07-21 21:58       ` Miguel Ojeda
  0 siblings, 0 replies; 8+ messages in thread
From: Miguel Ojeda @ 2025-07-21 21:58 UTC (permalink / raw)
  To: Benno Lossin
  Cc: Alice Ryhl, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein, Dirk Behme,
	Kartik Prajapati, Aliet Exposito Garcia, rust-for-linux,
	linux-kernel

On Mon, May 19, 2025 at 8:23 PM Benno Lossin <lossin@kernel.org> wrote:
>
> Another option would be to deprecate it. Do I remember correctly that
> Linus doesn't like that? If yes, then that maybe isn't a good idea...

Yeah, though for Rust we may need it sometimes during the "phased"
moves of items between Rust modules.

In this case, it is just not used upstream, and the only user
out-of-tree is easy to replace, so there is nothing stopping us from
just removing it.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rust: types: remove `Either<L, R>`
  2025-05-19 12:43 [PATCH] rust: types: remove `Either<L, R>` Benno Lossin
  2025-05-19 17:14 ` Danilo Krummrich
  2025-05-19 17:30 ` Alice Ryhl
@ 2025-07-21 21:59 ` Miguel Ojeda
  2 siblings, 0 replies; 8+ messages in thread
From: Miguel Ojeda @ 2025-07-21 21:59 UTC (permalink / raw)
  To: Benno Lossin
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein, Dirk Behme,
	Kartik Prajapati, Aliet Exposito Garcia, rust-for-linux,
	linux-kernel

On Mon, May 19, 2025 at 2:43 PM Benno Lossin <lossin@kernel.org> wrote:
>
> This enum is not used. Additionally, using it would result in poor
> ergonomics, because in order to do any operation on a value it has to be
> matched first. Our version of `Either` also doesn't provide any helper
> methods making it even more difficult to use.
>
> The alternative of creating a custom enum for the concrete use-case also
> is much better for ergonomics. As one can provide functions on the type
> directly and users don't need to match the value manually.
>
> Signed-off-by: Benno Lossin <lossin@kernel.org>

Applied to `rust-next` -- thanks everyone!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-21 21:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19 12:43 [PATCH] rust: types: remove `Either<L, R>` Benno Lossin
2025-05-19 17:14 ` Danilo Krummrich
2025-05-19 17:30 ` Alice Ryhl
2025-05-19 18:08   ` Miguel Ojeda
2025-05-19 18:12     ` Alice Ryhl
2025-05-19 18:23     ` Benno Lossin
2025-07-21 21:58       ` Miguel Ojeda
2025-07-21 21:59 ` Miguel Ojeda

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).