lkml.org 
[lkml]   [2022]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 27/28] rust: types: add `Either` type
On Fri, 2 Dec 2022 15:41:59 -0800
Josh Triplett <josh@joshtriplett.org> wrote:

> On Fri, Dec 02, 2022 at 05:14:58PM +0100, ojeda@kernel.org wrote:
> > From: Wedson Almeida Filho <wedsonaf@gmail.com>
> >
> > Introduce the new `types` module of the `kernel` crate with
> > `Either` as its first type.
> >
> > `Either<L, R>` is a sum type that always holds either a value
> > of type `L` (`Left` variant) or `R` (`Right` variant).
> >
> > For instance:
> >
> > struct Executor {
> > queue: Either<BoxedQueue, &'static Queue>,
> > }
>
> This specific example seems like it would be better served by the
> existing `Cow` type.

We use `no_global_oom_handling`, which gates most `ToOwned`
implementations (e.g. `str` cannot implement `to_owned()` because it
cannot guarantee allocation success).

So the Rust `Cow` is pretty much useless in the kernel.

Best,
Gary

\
 
 \ /
  Last update: 2022-12-04 11:32    [W:0.187 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site