aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
authorHsiu Che Yu <yu.whisper.personal@gmail.com>2026-04-25 18:16:18 +0800
committerDanilo Krummrich <dakr@kernel.org>2026-05-12 14:00:03 +0200
commit802ca0008bba0b9a27479580c3c77b9e8095c4ef (patch)
tree0a9cea59551f609c22eecec4f4ad563951b726ae /rust
parent75619f2df7a5da6ffb61eedc2a73fdf70c65471c (diff)
downloadlinux-next-history-802ca0008bba0b9a27479580c3c77b9e8095c4ef.tar.gz
rust: alloc: add doc test for `Vec::extend_with`
Add a doc test for `Vec::extend_with` demonstrating basic usage and the zero-length case. Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Tested-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://patch.msgid.link/a02bc604cde78ba505441a5555400e6f575e8a8a.1777111268.git.yu.whisper.personal@gmail.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r--rust/kernel/alloc/kvec.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index 0432864d3c3cc..76cbcfb73be2b 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -849,6 +849,24 @@ impl<T> Vec<T, KVmalloc> {
impl<T: Clone, A: Allocator> Vec<T, A> {
/// Extend the vector by `n` clones of `value`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// let mut v = KVec::new();
+ /// v.push(1, GFP_KERNEL)?;
+ ///
+ /// v.extend_with(3, 5, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5]);
+ ///
+ /// v.extend_with(2, 8, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]);
+ ///
+ /// v.extend_with(0, 3, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]);
+ ///
+ /// # Ok::<(), Error>(())
+ /// ```
pub fn extend_with(&mut self, n: usize, value: T, flags: Flags) -> Result<(), AllocError> {
if n == 0 {
return Ok(());