Commit d4073170 authored by Nell Shamrell-Harrington's avatar Nell Shamrell-Harrington Committed by Miguel Ojeda
Browse files

rust: types: add examples for the `Either` type



We aim to have examples in all Rust types, thus add basic ones for the
`Either` type.

Suggested-by: default avatarMiguel Ojeda <ojeda@kernel.org>
Signed-off-by: default avatarNell Shamrell-Harrington <nells@linux.microsoft.com>
Tested-by: default avatarDirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: default avatarTrevor Gross <tmgross@umich.edu>
Reviewed-by: default avatarAlice 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: default avatarMiguel Ojeda <ojeda@kernel.org>
parent 38f022b0
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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),