Skip to contentSkip to conversation

rust: alloc: add doc test for `Vec::from_elem`

PATCH In review Hsiu Che Yu 2 participants 5 messages Apr 26 – Apr 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: alloc: add doc test for `Vec::from_elem`

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

---
 rust/kernel/alloc/kvec.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)
rust/kernel/alloc/kvec.rs +12 -0
index ac8d6f763ae8..f5d213b4f715 100644
@@ -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,

Signature · 1 line
Hsiu Che Yu <[email protected]>
#2 lore raw
Quoted 2 lines · Alexandre Courbot

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

Quoted 4 lines · Alexandre Courbot

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

#3 lore raw
Quoted 10 lines · Hsiu Che Yu
Quoted 2 lines · Alexandre Courbot

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

Quoted 4 lines · Alexandre Courbot

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. :)

Quoted 5 lines

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).

Quoted 4 lines

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/

#4 lore raw
Quoted 6 lines · Alexandre Courbot

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).

I think I now understand the distinction between a patch series and individual patches. For independent changes, I'll just send them as separate patches.

Quoted 4 lines · Alexandre Courbot

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/

I've just started using b4, and it has been really helpful — it takes care of a lot of things that previously required juggling multiple tools.

Thanks,
Hsiu