replace_with_pad_space

Function replace_with_pad_space 

Source
pub fn replace_with_pad_space<'a>(
    s: &'a mut str,
    r: &str,
) -> Result<&'a mut str, ReplacementTooLong>
Expand description

Replace the str with another of the same length or shorter. The remaining bytes will be filled with spaces.

use mut_str::replace_with_pad_space;

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

replace_with_pad_space(&mut *owned_s, "๐ŸŒ").unwrap();
assert_eq!(&*owned_s, "๐ŸŒ  ");

replace_with_pad_space(&mut *owned_s, "aaaa").unwrap();
assert_eq!(&*owned_s, "aaaa  ");

ยงErrors

  • If r, when utf8 encoded, is longer than s, when utf8 encoded, ReplacementTooLong will be returned.