Trait stdext::vec::VecExtClone

source ·
pub trait VecExtClone<T: Clone> {
    // Required method
    fn resize_up(&mut self, new_len: usize, value: T);
}
Expand description

Extension trait with useful methods for std::vec::Vec.

This trait contains functions that require T to implement Clone trait.

Required Methods§

source

fn resize_up(&mut self, new_len: usize, value: T)

Resizes the Vec in-place if the provided new_len is greater than the current Vec length.

In simple words, this method only make vector bigger, but not smaller. Calling this method with a length smaller or equal to the current length will do nothing.

This method requires T to implement Clone, in order to be able to clone the passed value. If you need more flexibility (or want to rely on Default instead of Clone), use resize_up_with.

§Examples
use stdext::prelude::*;

let mut vec = vec!["hello"];
vec.resize_up(3, "world");
assert_eq!(vec, ["hello", "world", "world"]);

let mut vec = vec![1, 2, 3, 4];
vec.resize_up(2, 0);
assert_eq!(vec, [1, 2, 3, 4]); // Resizing to smaller size does nothing.

Implementations on Foreign Types§

source§

impl<T: Clone> VecExtClone<T> for Vec<T>

source§

fn resize_up(&mut self, new_len: usize, value: T)

Implementors§