pub fn replace<'a>(s: &'a mut str, r: &str) -> Result<&'a mut str, LenNotEqual>
Expand description
Replace the str
with another of the same length.
use mut_str::replace;
let mut owned_s = Box::<str>::from("World!");
replace(&mut *owned_s, "🌍!!").unwrap();
assert_eq!(&*owned_s, "🌍!!");
replace(&mut *owned_s, "aaaaaa").unwrap();
assert_eq!(&*owned_s, "aaaaaa");
§Errors
- If
s
andr
, when utf8 encoded, do not have the same length,LenNotEqual
will be returned.