center

Function center 

Source
pub fn center(s: &str, width: usize) -> String
Expand description

Returns a centered string of length width.

Padding is done with spaces.

It’s similar to Python’s str.center().

§Examples

let text = "*";
let result = jabba_lib::jstring::center(text, 3);

assert_eq!(result, " * ");
Examples found in repository?
examples/string.rs (line 10)
3fn main() {
4    let name = "Laci";
5    println!("{} <-> {}", name, jstring::str_rev(name));
6
7    let name = "anna";
8    println!("{} is palindrome: {}", name, jstring::is_palindrome(name));
9
10    println!("{:?}", jstring::center("-", 3));
11}