Function left_pad::leftpad [] [src]

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

Pads a string to the given number of chars by inserting spaces from the left.

If the given string has more than or exactly the desired number of codepoints, it will be returned as-is.

Codepoints are not graphemes, so the result might not always be what a human would expect.

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

Examples

use left_pad::{leftpad,leftpad_with};

assert_eq!(leftpad("blübb", 7), "  blübb");

assert_eq!(leftpad("blübb", 5), "blübb");
assert_eq!(leftpad("blübb", 3), "blübb");

assert_eq!(leftpad("blübb", 7), leftpad_with("blübb", 7, ' '));

assert_eq!(leftpad("čömbiñiñg märks", 22),  "  čömbiñiñg märks");