Function mut_str::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.