public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: alloc: add doc test for `Vec::from_elem`
@ 2026-04-26  3:46 Hsiu Che Yu
  2026-04-26  4:05 ` Alexandre Courbot
  0 siblings, 1 reply; 4+ messages in thread
From: Hsiu Che Yu @ 2026-04-26  3:46 UTC (permalink / raw)
  To: Danilo Krummrich, Lorenzo Stoakes, Vlastimil Babka,
	Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross
  Cc: rust-for-linux, linux-kernel, Hsiu Che Yu

Add a doc test for `Vec::from_elem` demonstrating basic usage and the
zero-length case.

Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
---
 rust/kernel/alloc/kvec.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index ac8d6f763ae8..f5d213b4f715 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -792,6 +792,18 @@ pub fn extend_from_slice(&mut self, other: &[T], flags: Flags) -> Result<(), All
     }
 
     /// Create a new `Vec<T, A>` and extend it by `n` clones of `value`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// let v = KVec::from_elem(1, 5, GFP_KERNEL)?;
+    /// assert_eq!(&v, &[1, 1, 1, 1, 1]);
+    ///
+    /// let v = KVec::from_elem(1, 0, GFP_KERNEL)?;
+    /// assert!(v.is_empty());
+    ///
+    /// # Ok::<(), Error>(())
+    /// ```
     pub fn from_elem(value: T, n: usize, flags: Flags) -> Result<Self, AllocError> {
         let mut v = Self::with_capacity(n, flags)?;
 

---
base-commit: b4e07588e743c989499ca24d49e752c074924a9a
change-id: 20260426-doctest-alloc-kvec-from_elem-bb8eb3782978

Best regards,
--  
Hsiu Che Yu <yu.whisper.personal@gmail.com>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: alloc: add doc test for `Vec::from_elem`
  2026-04-26  3:46 [PATCH] rust: alloc: add doc test for `Vec::from_elem` Hsiu Che Yu
@ 2026-04-26  4:05 ` Alexandre Courbot
  2026-04-26  4:27   ` Hsiu Che Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Courbot @ 2026-04-26  4:05 UTC (permalink / raw)
  To: Hsiu Che Yu
  Cc: Danilo Krummrich, Lorenzo Stoakes, Vlastimil Babka,
	Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, rust-for-linux, linux-kernel

On Sun Apr 26, 2026 at 12:46 PM JST, Hsiu Che Yu wrote:
> Add a doc test for `Vec::from_elem` demonstrating basic usage and the
> zero-length case.
>
> Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>

Received just as I had finished testing your other series. :) So while
I'm at it:

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Alexandre Courbot <acourbot@nvidia.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: alloc: add doc test for `Vec::from_elem`
  2026-04-26  4:05 ` Alexandre Courbot
@ 2026-04-26  4:27   ` Hsiu Che Yu
  2026-04-26 13:11     ` Alexandre Courbot
  0 siblings, 1 reply; 4+ messages in thread
From: Hsiu Che Yu @ 2026-04-26  4:27 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Hsiu Che Yu, Danilo Krummrich, Lorenzo Stoakes, Vlastimil Babka,
	Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, rust-for-linux, linux-kernel

On Sun, Apr 26, 2026 at 01:05:36PM +0900, Alexandre Courbot wrote:
>Received just as I had finished testing your other series. :) So while
>I'm at it:

On Sun, Apr 26, 2026 at 01:00:06PM +0900, Alexandre Courbot wrote:
>Looking good - just one thing, when sending a new revision of a
>patchset, please start a new thread instead of replying to the previous
>one. Otherwise things can get pretty hard to follow once we arrive at,
>say, v10. :)

I just realized — should I have grouped the tests targeting the same 
module into a single patch series (like the one that was split into
two recently)?
Would that make the review process easier? If so, I'll start batching
small doc-test patches together before sending.

Also, as you pointed out in your other reply, 
I had confused `link:` and `in-reply-to`. 
I'll make sure to use `link:` to reference context for v2 onwards.

Thanks,
Hsiu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: alloc: add doc test for `Vec::from_elem`
  2026-04-26  4:27   ` Hsiu Che Yu
@ 2026-04-26 13:11     ` Alexandre Courbot
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Courbot @ 2026-04-26 13:11 UTC (permalink / raw)
  To: Hsiu Che Yu
  Cc: Danilo Krummrich, Lorenzo Stoakes, Vlastimil Babka,
	Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, rust-for-linux, linux-kernel

On Sun Apr 26, 2026 at 1:27 PM JST, Hsiu Che Yu wrote:
> On Sun, Apr 26, 2026 at 01:05:36PM +0900, Alexandre Courbot wrote:
>>Received just as I had finished testing your other series. :) So while
>>I'm at it:
>
> On Sun, Apr 26, 2026 at 01:00:06PM +0900, Alexandre Courbot wrote:
>>Looking good - just one thing, when sending a new revision of a
>>patchset, please start a new thread instead of replying to the previous
>>one. Otherwise things can get pretty hard to follow once we arrive at,
>>say, v10. :)
>
> I just realized — should I have grouped the tests targeting the same 
> module into a single patch series (like the one that was split into
> two recently)?
> Would that make the review process easier? If so, I'll start batching
> small doc-test patches together before sending.

I don't think there is any hard rule, but usually a patch series implies
a dependency between the patches, i.e. patch 2 cannot build without
patch 1. For what you sent so far this is not the case, so separate
patches is fine and maybe even preferable as they can be applied
individually whereas maintainers tend to consider series as "all or
nothing" (there are exceptions of course).

>
> Also, as you pointed out in your other reply, 
> I had confused `link:` and `in-reply-to`. 
> I'll make sure to use `link:` to reference context for v2 onwards.

No worries. If I may recommend b4 [1] for managing your patch series, it
ususally just does the right thing for you.

[1] https://b4.docs.kernel.org/en/latest/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-26 13:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-26  3:46 [PATCH] rust: alloc: add doc test for `Vec::from_elem` Hsiu Che Yu
2026-04-26  4:05 ` Alexandre Courbot
2026-04-26  4:27   ` Hsiu Che Yu
2026-04-26 13:11     ` Alexandre Courbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox