Function mut_str::replace_with_pad

source ·
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