public inbox for linux-kernel@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; 5+ 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] 5+ messages in thread

end of thread, other threads:[~2026-04-27  4:08 UTC | newest]

Thread overview: 5+ 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
2026-04-27  4:08       ` Hsiu Che Yu

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