mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
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>
This commit is contained in:
parent
75619f2df7
commit
802ca0008b
|
|
@ -849,6 +849,24 @@ pub fn shrink_to(&mut self, min_capacity: usize, flags: Flags) -> Result<(), All
|
|||
|
||||
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(());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user