Function left_pad::leftpad [] [src]

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

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

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

This function is equal to calling leftpad_with(string, len, ' ').

Examples

use left_pad::leftpad;

assert_eq!(leftpad("blubb", 7), "  blubb");

assert_eq!(leftpad("blubb", 5), "blubb");
assert_eq!(leftpad("blubb", 3), "blubb");

use left_pad::leftpad_with;

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