From: ojeda@kernel.org
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"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>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@lists.linux.dev, Wei Liu <wei.liu@kernel.org>
Subject: [PATCH v2 27/28] rust: types: add `Either` type
Date: Fri, 2 Dec 2022 17:14:58 +0100 [thread overview]
Message-ID: <20221202161502.385525-28-ojeda@kernel.org> (raw)
In-Reply-To: <20221202161502.385525-1-ojeda@kernel.org>
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>,
}
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
rust/kernel/lib.rs | 1 +
rust/kernel/types.rs | 12 ++++++++++++
2 files changed, 13 insertions(+)
create mode 100644 rust/kernel/types.rs
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index a3abc110ff97..53040fa9e897 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -31,6 +31,7 @@ mod static_assert;
#[doc(hidden)]
pub mod std_vendor;
pub mod str;
+pub mod types;
#[doc(hidden)]
pub use bindings;
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
new file mode 100644
index 000000000000..3b0c44769708
--- /dev/null
+++ b/rust/kernel/types.rs
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Kernel types.
+
+/// A sum type that always holds either a value of type `L` or `R`.
+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),
+}
--
2.38.1
next prev parent reply other threads:[~2022-12-02 16:18 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-02 16:14 [PATCH v2 00/28] Rust core additions ojeda
2022-12-02 16:14 ` [PATCH v2 01/28] rust: prelude: split re-exports into groups ojeda
2022-12-02 16:14 ` [PATCH v2 02/28] rust: print: add more `pr_*!` levels ojeda
2022-12-02 16:14 ` [PATCH v2 03/28] rust: print: add `pr_cont!` macro ojeda
2022-12-02 16:14 ` [PATCH v2 04/28] rust: samples: add `rust_print` example ojeda
2022-12-02 16:14 ` [PATCH v2 05/28] rust: macros: add `concat_idents!` proc macro ojeda
2022-12-04 0:20 ` Gary Guo
2022-12-02 16:14 ` [PATCH v2 06/28] rust: macros: add `#[vtable]` " ojeda
2022-12-06 12:49 ` Finn Behrens
2022-12-06 15:44 ` Miguel Ojeda
2022-12-02 16:14 ` [PATCH v2 07/28] rust: macros: take string literals in `module!` ojeda
2022-12-02 16:14 ` [PATCH v2 08/28] rust: error: declare errors using macro ojeda
2022-12-02 16:14 ` [PATCH v2 09/28] rust: error: add codes from `errno-base.h` ojeda
2022-12-06 12:52 ` Finn Behrens
2022-12-02 16:14 ` [PATCH v2 10/28] rust: error: add `From` implementations for `Error` ojeda
2022-12-02 16:14 ` [PATCH v2 11/28] rust: prelude: add `error::code::*` constant items ojeda
2022-12-02 16:14 ` [PATCH v2 12/28] rust: alloc: add `RawVec::try_with_capacity_in()` constructor ojeda
2022-12-02 16:14 ` [PATCH v2 13/28] rust: alloc: add `Vec::try_with_capacity{,_in}()` constructors ojeda
2022-12-06 12:55 ` Finn Behrens
2022-12-02 16:14 ` [PATCH v2 14/28] rust: str: add `BStr` type ojeda
2022-12-02 16:14 ` [PATCH v2 15/28] rust: str: add `b_str!` macro ojeda
2022-12-02 16:14 ` [PATCH v2 16/28] rust: str: add `CStr` type ojeda
2022-12-02 16:14 ` [PATCH v2 17/28] rust: str: implement several traits for `CStr` ojeda
2022-12-02 16:14 ` [PATCH v2 18/28] rust: str: add `CStr` unit tests ojeda
2022-12-02 16:14 ` [PATCH v2 19/28] rust: str: add `c_str!` macro ojeda
2022-12-02 16:14 ` [PATCH v2 20/28] rust: str: add `Formatter` type ojeda
2022-12-04 15:41 ` Dr. David Alan Gilbert
2022-12-04 17:26 ` Wedson Almeida Filho
2022-12-04 18:05 ` Dr. David Alan Gilbert
2022-12-02 16:14 ` [PATCH v2 21/28] rust: str: add `CString` type ojeda
2022-12-02 16:14 ` [PATCH v2 22/28] rust: str: add `fmt!` macro ojeda
2022-12-02 16:14 ` [PATCH v2 23/28] rust: std_vendor: add `dbg!` macro based on `std`'s one ojeda
2022-12-02 16:14 ` [PATCH v2 24/28] rust: static_assert: add `static_assert!` macro ojeda
2022-12-02 16:14 ` [PATCH v2 25/28] rust: add `build_error` crate ojeda
2022-12-02 18:31 ` Wei Liu
2022-12-02 16:14 ` [PATCH v2 26/28] rust: build_assert: add `build_{error,assert}!` macros ojeda
2022-12-02 18:32 ` Wei Liu
2022-12-02 16:14 ` ojeda [this message]
2022-12-02 23:41 ` [PATCH v2 27/28] rust: types: add `Either` type Josh Triplett
2022-12-04 0:58 ` Miguel Ojeda
2022-12-04 10:31 ` Gary Guo
2022-12-04 17:36 ` Wedson Almeida Filho
2022-12-05 13:53 ` Miguel Ojeda
2022-12-05 23:00 ` Josh Triplett
2022-12-02 16:14 ` [PATCH v2 28/28] rust: types: add `Opaque` type ojeda
2022-12-04 1:05 ` [PATCH v2 00/28] Rust core additions Miguel Ojeda
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=20221202161502.385525-28-ojeda@kernel.org \
--to=ojeda@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
--cc=wei.liu@kernel.org \
/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 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).