replace_with_pad_left_space

Function replace_with_pad_left_space 

Source
pub fn replace_with_pad_left_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, right aligned. The remaining bytes before the str will be filled with spaces.

use mut_str::replace_with_pad_left_space;

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

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

replace_with_pad_left_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.