Function mut_str::replace_with_pad_left_char

source ·
pub fn replace_with_pad_left_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, right aligned. The remaining bytes before the str will be filled with char, which must be one byte long.

use mut_str::replace_with_pad_left_char;

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

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

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

§Errors