Skip to contentSkip to conversation

rust: Adds examples for the `Either` type

PATCH Superseded Nell Shamrell-Harrington 2 participants 3 messages Sep 16, 2024 – Sep 17, 2024 Rust

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: Adds examples for the `Either` type

Adds examples for the Either type

---
 rust/kernel/types.rs | 6 ++++++
 1 file changed, 6 insertions(+)
rust/kernel/types.rs +6 -0
index 9e7ca066355c..f22f6e289198 100644
@@ -461,6 +461,12 @@ fn drop(&mut self) {
 }
 
 /// A sum type that always holds either a value of type `L` or `R`.
+/// ```
+/// 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),
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw
Quoted 1 line · Nell Shamrell-Harrington

Adds examples for the Either type

You might want to check

https://www.kernel.org/doc/html/latest/process/submitting-patches.html

"Describe your changes in imperative mood, e.g. “make xyzzy do frotz” instead of “[This patch] makes xyzzy do frotz” or “[I] changed xyzzy to do frotz”, as if you are giving orders to the codebase to change its behaviour."

For example:

[PATCH] rust: types: Add examples for the Either type

Add examples for the Either types.

Quoted 11 lines
---
  rust/kernel/types.rs | 6 ++++++
  1 file changed, 6 insertions(+)
rust/kernel/types.rs +0 -0
index 9e7ca066355c..f22f6e289198 100644

rust/kernel/types.rs fn drop(&mut self) { · line 463

Quoted 3 lines
rust/kernel/types.rs +0 -0
@@ -461,6 +461,12 @@ fn drop(&mut self) {
  }
 
  /// A sum type that always holds either a value of type `L` or `R`.

It looks to me that the default is to add

/// # Examples

followed by some verbose explanation before the test code below.

rust/kernel/types.rs fn drop(&mut self) { · line 469

Quoted 6 lines
rust/kernel/types.rs +6 -0
+/// ```
+/// use kernel::types::Either;
+///
+/// let left_value: Either<i32, &str> = Either::Left(7);
+/// let right_value: Either<i32, &str> = Either::Right("right value");
+/// ```

I ran that on the the target and got:

# rust_doctest_kernel_types_rs_3.location: rust/kernel/types.rs:485 ok 107 rust_doctest_kernel_types_rs_3

So:

Thanks

Dirk

#2 lore raw
Quoted 12 lines · Dirk Behme
Quoted 1 line · Nell Shamrell-Harrington

Adds examples for the Either type

You might want to check

https://www.kernel.org/doc/html/latest/process/submitting-patches.html

"Describe your changes in imperative mood, e.g. “make xyzzy do frotz” instead of “[This patch] makes xyzzy do frotz” or “[I] changed xyzzy to do frotz”, as if you are giving orders to the codebase to change its behaviour."

Quoted 5 lines

For example:

[PATCH] rust: types: Add examples for the Either type

Add examples for the Either types.

Will do!

Quoted 18 lines
Quoted 13 lines
---
 rust/kernel/types.rs | 6 ++++++
 1 file changed, 6 insertions(+)
rust/kernel/types.rs +0 -0
index 9e7ca066355c..f22f6e289198 100644

rust/kernel/types.rs fn drop(&mut self) { · line 462

Quoted 2 lines
rust/kernel/types.rs +0 -0
@@ -461,6 +461,12 @@ fn drop(&mut self) {
 }
 /// A sum type that always holds either a value of type `L` or `R`.

It looks to me that the default is to add

Quoted 1 line

/// # Examples

Thank you, I will add this in and resubmit the patch.

Quoted 12 lines

followed by some verbose explanation before the test code below.

rust/kernel/types.rs fn drop(&mut self) { · line 469

Quoted 6 lines
rust/kernel/types.rs +6 -0
+/// ```
+/// use kernel::types::Either;
+///
+/// let left_value: Either<i32, &str> = Either::Left(7);
+/// let right_value: Either<i32, &str> = Either::Right("right value");
+/// ```

I ran that on the the target and got:

Quoted 6 lines

# rust_doctest_kernel_types_rs_3.location: rust/kernel/types.rs:485 ok 107 rust_doctest_kernel_types_rs_3

So:

Thank you for doing this, I appreciate you taking the time!

Quoted 6 lines

Thanks

Dirk