Function mut_str::replace_with_pad_char

source ·
pub fn replace_with_pad_char<'a, C>(
    s: &'a mut str,
    r: &str,
    pad_char: C
) -> Result<&'a mut str, ReplaceWithPadCharError>
where C: Into<char>,
Expand description

Replace the str with another of the same length or shorter. The remaining bytes will be filled with pad, which must be one byte long.

use mut_str::replace_with_pad_char;

let mut owned_s = Box::<str>::from("World!");

replace_with_pad_char(&mut *owned_s, "🌍", '!').unwrap();
assert_eq!(&*owned_s, "🌍!!");

replace_with_pad_char(&mut *owned_s, "aaaa", 'b').unwrap();
assert_eq!(&*owned_s, "aaaabb");

§Errors