pub fn replace_with_pad<'a>(
s: &'a mut str,
r: &str,
pad: u8,
) -> Result<&'a mut str, ReplaceWithPadError>Expand description
Replace the str with another of the same length or shorter.
The remaining bytes will be filled with pad.
use mut_str::replace_with_pad;
let mut owned_s = Box::<str>::from("World!");
replace_with_pad(&mut *owned_s, "๐", b'!').unwrap();
assert_eq!(&*owned_s, "๐!!");
replace_with_pad(&mut *owned_s, "aaaa", b'b').unwrap();
assert_eq!(&*owned_s, "aaaabb");ยงErrors
- If
padis not valid utf8,ReplaceWithPadError::InvalidPadwill be returned. - If
r, when utf8 encoded, is longer thans, when utf8 encoded,ReplaceWithPadError::ReplacementLenwill be returned.