public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] rust: types: Add examples for the `Either` type
@ 2024-09-18 21:20 Nell Shamrell-Harrington
  2024-09-29 21:38 ` Trevor Gross
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nell Shamrell-Harrington @ 2024-09-18 21:20 UTC (permalink / raw)
  To: ojeda, alex.gaynor, wedsonaf
  Cc: boqun.feng, gary, bjorn3_gh, benno.lossin, a.hindborg, aliceryhl,
	tmgross, linux, kernel, kent.overstreet, matthew.d.roper,
	kartikprajapati987, rust-for-linux, linux-kernel

Add examples 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>
---
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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-07 18:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-18 21:20 [PATCH v2] rust: types: Add examples for the `Either` type Nell Shamrell-Harrington
2024-09-29 21:38 ` Trevor Gross
2024-09-30  7:56 ` Alice Ryhl
2024-10-01 22:57 ` Miguel Ojeda
2024-10-07 15:53   ` [PATCH] rust: types: 'real-life' example for Either Timo Grautstueck
2024-10-07 18:47     ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox