projects
/
linux-2.6-microblaze.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
38f022b
)
rust: types: add examples for the `Either` type
author
Nell Shamrell-Harrington
<nells@linux.microsoft.com>
Wed, 18 Sep 2024 21:20:52 +0000
(21:20 +0000)
committer
Miguel Ojeda
<ojeda@kernel.org>
Mon, 7 Oct 2024 08:49:15 +0000
(10:49 +0200)
We aim to have examples in all Rust types, thus add basic ones for the
`Either` type.
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Nell Shamrell-Harrington <nells@linux.microsoft.com>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link:
https://rust-for-linux.zulipchat.com/#narrow/stream/291565/topic/x/near/467478085
Link:
https://lore.kernel.org/r/20240918212052.8790-1-nells@linux.microsoft.com
[ Reworded slightly. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/types.rs
patch
|
blob
|
history
diff --git
a/rust/kernel/types.rs
b/rust/kernel/types.rs
index
9e7ca06
..
e2f3ab1
100644
(file)
--- a/
rust/kernel/types.rs
+++ b/
rust/kernel/types.rs
@@
-461,6
+461,15
@@
impl<T: AlwaysRefCounted> Drop for ARef<T> {
}
/// 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),