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>
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
- If
pad_char
, when utf8 encoded, is longer thanSelf
,ReplaceWithPadCharError::PadCharTooLong
will be returned. - If
r
, when utf8 encoded, is longer thans
, when utf8 encoded,ReplaceWithPadCharError::ReplacementLen
will be returned.