From: Nell Shamrell-Harrington <nells@linux.microsoft.com>
To: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com
Cc: boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, a.hindborg@samsung.com,
aliceryhl@google.com, tmgross@umich.edu, linux@obei.io,
kernel@valentinobst.de, kent.overstreet@gmail.com,
matthew.d.roper@intel.com, kartikprajapati987@gmail.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] rust: types: Add examples for the `Either` type
Date: Wed, 18 Sep 2024 21:20:52 +0000 [thread overview]
Message-ID: <20240918212052.8790-1-nells@linux.microsoft.com> (raw)
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
next reply other threads:[~2024-09-18 21:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-18 21:20 Nell Shamrell-Harrington [this message]
2024-09-29 21:38 ` [PATCH v2] rust: types: Add examples for the `Either` type 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
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=20240918212052.8790-1-nells@linux.microsoft.com \
--to=nells@linux.microsoft.com \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=kartikprajapati987@gmail.com \
--cc=kent.overstreet@gmail.com \
--cc=kernel@valentinobst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@obei.io \
--cc=matthew.d.roper@intel.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=wedsonaf@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.