Function left_pad::leftpad_with [] [src]

pub fn leftpad_with<'a, S>(
    string: S,
    len: usize,
    pad_char: char
) -> Cow<'a, str> where
    S: Into<Cow<'a, str>>, 

Pads a string to the given length len by inserting the character pad_char from the left.

If the given string has a length longer or equal to the desired length, it will be returned as-is.

Examples

use left_pad::leftpad_with;

assert_eq!(leftpad_with("blubb", 7, ' '), "  blubb");
assert_eq!(leftpad_with("blubb", 7, '.'), "..blubb");

assert_eq!(leftpad_with("blubb", 5, ' '), "blubb");
assert_eq!(leftpad_with("blubb", 3, ' '), "blubb");