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