Skip to content

Commit c94d8cd

Browse files
Nell Shamrell-Harringtonojeda
Nell Shamrell-Harrington
authored andcommitted
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: Miguel Ojeda <[email protected]> Signed-off-by: Nell Shamrell-Harrington <[email protected]> Tested-by: Dirk Behme <[email protected]> Reviewed-by: Trevor Gross <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://rust-for-linux.zulipchat.com/#narrow/stream/291565/topic/x/near/467478085 Link: https://lore.kernel.org/r/[email protected] [ Reworded slightly. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 2db6795 commit c94d8cd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

rust/kernel/types.rs

+9
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,15 @@ impl<T: AlwaysRefCounted> Drop for ARef<T> {
461461
}
462462

463463
/// A sum type that always holds either a value of type `L` or `R`.
464+
///
465+
/// # Examples
466+
///
467+
/// ```
468+
/// use kernel::types::Either;
469+
///
470+
/// let left_value: Either<i32, &str> = Either::Left(7);
471+
/// let right_value: Either<i32, &str> = Either::Right("right value");
472+
/// ```
464473
pub enum Either<L, R> {
465474
/// Constructs an instance of [`Either`] containing a value of type `L`.
466475
Left(L),

0 commit comments

Comments
 (0)