public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Hsiu Che Yu <yu.whisper.personal@gmail.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Hsiu Che Yu <yu.whisper.personal@gmail.com>
Subject: [PATCH] rust: alloc: add doc test for `Vec::from_elem`
Date: Sun, 26 Apr 2026 11:46:27 +0800	[thread overview]
Message-ID: <20260426-doctest-alloc-kvec-from_elem-v1-1-e364341a759b@gmail.com> (raw)

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>


             reply	other threads:[~2026-04-26  3:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-26  3:46 Hsiu Che Yu [this message]
2026-04-26  4:05 ` [PATCH] rust: alloc: add doc test for `Vec::from_elem` 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260426-doctest-alloc-kvec-from_elem-v1-1-e364341a759b@gmail.com \
    --to=yu.whisper.personal@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox