Skip to content

Commit 802ca00

Browse files
Hsiu Che YuDanilo Krummrich
authored andcommitted
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>
1 parent 75619f2 commit 802ca00

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎rust/kernel/alloc/kvec.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,24 @@ impl<T> Vec<T, KVmalloc> {
849849

850850
impl<T: Clone, A: Allocator> Vec<T, A> {
851851
/// Extend the vector by `n` clones of `value`.
852+
///
853+
/// # Examples
854+
///
855+
/// ```
856+
/// let mut v = KVec::new();
857+
/// v.push(1, GFP_KERNEL)?;
858+
///
859+
/// v.extend_with(3, 5, GFP_KERNEL)?;
860+
/// assert_eq!(&v, &[1, 5, 5, 5]);
861+
///
862+
/// v.extend_with(2, 8, GFP_KERNEL)?;
863+
/// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]);
864+
///
865+
/// v.extend_with(0, 3, GFP_KERNEL)?;
866+
/// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]);
867+
///
868+
/// # Ok::<(), Error>(())
869+
/// ```
852870
pub fn extend_with(&mut self, n: usize, value: T, flags: Flags) -> Result<(), AllocError> {
853871
if n == 0 {
854872
return Ok(());

0 commit comments

Comments
 (0)