pub fn replace_with_pad_left_char<'a, C>(
s: &'a mut str,
r: &str,
pad_char: C,
) -> Result<&'a mut str, ReplaceWithPadCharError>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
- If
pad_char, when utf8 encoded, is longer thanSelf,ReplaceWithPadCharError::PadCharTooLongwill be returned. - If
r, when utf8 encoded, is longer thans, when utf8 encoded,ReplaceWithPadCharError::ReplacementLenwill be returned.