[PATCH v2] rust: types: Add examples for the `Either` type

From: Nell Shamrell-Harrington
Date: Wed Sep 18 2024 - 17:21:22 EST


Add examples for the `Either` type

Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
Signed-off-by: Nell Shamrell-Harrington <nells@xxxxxxxxxxxxxxxxxxx>
Tested-by: Dirk Behme <dirk.behme@xxxxxxxxxxxx>
---
V1 -> V2: Cleaned up commit message and addressed review comments

rust/kernel/types.rs | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index 9e7ca066355c..e2f3ab11cfda 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -461,6 +461,15 @@ 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),
--
2.34.1