Function replace

Source
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 and r, when utf8 encoded, do not have the same length, LenNotEqual will be returned.