pub fn center(txt: &str, space: usize) -> Option<String> {
    // Determine the width of the characters when displayed
    let len = txt.width();
    // Return None if there is not enough space to fit the string
    if len > space {
        return None;
    }
    // Work out total space needed on each side
    let left_over = space - len;
    let each = left_over / 2;
    // Pad the left hand side
    let left_pad = " ".repeat(each);
    // Pad the right hand side
    let right_pad = " ".repeat(left_over - each);
    // Format and return
    Some(format!("{}{}{}", left_pad, txt, right_pad))
}
/// Aligns the text to the center
///
/// Will return `None` if there is not enough space to fit the text (length of txt > space)
Aligns the text to the center
Will return `None` if there is not enough space to fit the text (length of txt > space)
Aligns the text to the center Will return ` None ` if there is not enough space to fit the text ( length of txt > space )
pub fn center(txt: &str, space: usize) -> Option<String> {
    // Determine the width of the characters when displayed
    let len = txt.width();
    // Return None if there is not enough space to fit the string
    if len > space {
        return None;
    }
    // Work out total space needed on each side
    let left_over = space - len;
    let each = left_over / 2;
    // Pad the left hand side
    let left_pad = " ".repeat(each);
    // Pad the right hand side
    let right_pad = " ".repeat(left_over - each);
    // Format and return
    Some(format!("{}{}{}", left_pad, txt, right_pad))
}
pub fn center ( txt : & str , space : usize ) -> Option < String > { // Determine the width of the characters when displayed let len = txt . width ( ) ; // Return None if there is not enough space to fit the string if len > space { return None ; } // Work out total space needed on each side let left_over = space - len ; let each = left_over / 2 ; // Pad the left hand side let left_pad = " " . repeat ( each ) ; // Pad the right hand side let right_pad = " " . repeat ( left_over - each ) ; // Format and return Some ( format ! ( " " left_pad txt right_pad ) ) }
Aligns the text to the center
Will return `None` if there is not enough space to fit the text (length of txt > space)
Aligns the text to the center Will return ` None ` if there is not enough space to fit the text ( length of txt > space )
txt
&str
space
usize