[][src]Trait stdext::vec::VecExtClone

pub trait VecExtClone<T: Clone> {
    fn resize_up(&mut self, new_len: usize, value: T);

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

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

Required methods

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.


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.
Loading content...

Implementations on Foreign Types

impl<T: Clone> VecExtClone<T> for Vec<T>[src]

Loading content...


Loading content...