diff options
author | Wedson Almeida Filho <wedsonaf@gmail.com> | 2022-11-10 19:41:39 +0300 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2022-12-04 03:59:16 +0300 |
commit | ba20915bae49024dab6ee582abdd4cd8944a3e55 (patch) | |
tree | 58941383549263a3d2e39312d5c339a16a4296c4 /rust/kernel/types.rs | |
parent | 0f595bab9d1c1a10c6ab5ff3f9140cfc26600349 (diff) | |
download | linux-ba20915bae49024dab6ee582abdd4cd8944a3e55.tar.xz |
rust: types: add `Either` type
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>
Diffstat (limited to 'rust/kernel/types.rs')
-rw-r--r-- | rust/kernel/types.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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), +} |