pub fn replace_n<T: PartialEq + Clone>(
vec: &mut Vec<T>,
old: T,
new: T,
n: usize,
)Expand description
Replace the first count n old elements with new elements within the vector.
§Arguments
-
vec- The vector to replace. -
old- old item to be replaced. -
new- new item to replace. -
n- the number of old elements bo be replaced.
§Examples
use rufl::collection;
let mut vec = vec!["a", "b", "c", "b"];
let result = collection::replace_n(&mut vec, "b", "2", 1);
assert_eq!(vec!["a", "2", "c", "b"], vec);