Skip to content

Commit

Permalink
rust: types: add examples for the Either type
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Nell Shamrell-Harrington authored and herrnst committed Dec 6, 2024
1 parent 4a8e9c0 commit e46bf3e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rust/kernel/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,15 @@ impl<T: AlwaysRefCounted> Drop for ARef<T> {
}

/// 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),
Expand Down

0 comments on commit e46bf3e

Please sign in to comment.