pub fn between(txt: &[&str], space: usize) -> Option<String> {
    // Determine the width of the characters when displayed
    let len: usize = txt.iter().map(|x| x.width()).sum();
    // Return None if there is not enough space to fit the string
    if len > space {
        return None;
    }
    // Handle the case of there being < 2 columns provided
    if txt.is_empty() {
        return Some(" ".repeat(space));
    } else if txt.len() == 1 {
        return left(txt[0], space);
    }
    // Work out total space needed between the columns
    let left_over = space - len;
    let pad_places = txt.len().saturating_sub(1); // Number of places where padding is required
    let each = left_over / pad_places;
    let mut remainder = left_over - each * pad_places; // Remainder padding when space doesn't divide equally
                                                       // Begin formatting
    let mut result = "".to_string();
    for t in txt.iter().take(pad_places) {
        // Push text and padding
        result.push_str(t);
        result.push_str(&" ".repeat(each));
        // Redistribute any remainder padding
        if remainder > 0 {
            result.push(' ');
            remainder -= 1;
        }
    }
    // Push on final element
    result.push_str(txt.last().unwrap_or(&""));
    Some(result)
}
/// Adds space between the specified strings in the `txt` slice
///
/// Great for rendering a status line, or some kind of simple column set up
///
/// Will return `None` if there is not enough space to fit the text (length of txt > space)
///
/// Example:
/// ```
/// use alinio::align;
/// let result = align::between(&["Title", "Artist", "Album"], 20); // Format 3 columns into a space of 20
/// println!("{}", result.unwrap()); // -> "Title  Artist  Album"
/// ```
Adds space between the specified strings in the `txt` slice
Great for rendering a status line, or some kind of simple column set up

Will return `None` if there is not enough space to fit the text (length of txt > space)


Adds space between the specified strings in the ` txt ` slice Great for rendering a status line or some kind of simple column set up Will return ` None ` if there is not enough space to fit the text ( length of txt > space )
pub fn between(txt: &[&str], space: usize) -> Option<String> {
    // Determine the width of the characters when displayed
    let len: usize = txt.iter().map(|x| x.width()).sum();
    // Return None if there is not enough space to fit the string
    if len > space {
        return None;
    }
    // Handle the case of there being < 2 columns provided
    if txt.is_empty() {
        return Some(" ".repeat(space));
    } else if txt.len() == 1 {
        return left(txt[0], space);
    }
    // Work out total space needed between the columns
    let left_over = space - len;
    let pad_places = txt.len().saturating_sub(1); // Number of places where padding is required
    let each = left_over / pad_places;
    let mut remainder = left_over - each * pad_places; // Remainder padding when space doesn't divide equally
                                                       // Begin formatting
    let mut result = "".to_string();
    for t in txt.iter().take(pad_places) {
        // Push text and padding
        result.push_str(t);
        result.push_str(&" ".repeat(each));
        // Redistribute any remainder padding
        if remainder > 0 {
            result.push(' ');
            remainder -= 1;
        }
    }
    // Push on final element
    result.push_str(txt.last().unwrap_or(&""));
    Some(result)
}
pub fn between ( txt : & [ & str ] , space : usize ) -> Option < String > { // Determine the width of the characters when displayed let len : usize = txt . iter ( ) . map ( | x | x . width ( ) ) . sum ( ) ; // Return None if there is not enough space to fit the string if len > space { return None ; } // Handle the case of there being < 2 columns provided if txt . is_empty ( ) { return Some ( " " . repeat ( space ) ) ; } else if txt . len ( ) == 1 { return left ( txt [ 0 ] , space ) ; } // Work out total space needed between the columns let left_over = space - len ; let pad_places = txt . len ( ) . saturating_sub ( 1 ) ; // Number of places where padding is required let each = left_over / pad_places ; let mut remainder = left_over - each * pad_places ; // Remainder padding when space doesn't divide equally // Begin formatting let mut result = " " . to_string ( ) ; for t in txt . iter ( ) . take ( pad_places ) { // Push text and padding result . push_str ( t ) ; result . push_str ( & " " . repeat ( each ) ) ; // Redistribute any remainder padding if remainder > 0 { result . push ( ' ' ) ; remainder -= 1 ; } } // Push on final element result . push_str ( txt . last ( ) . unwrap_or ( & " " ) ) ; Some ( result ) }
Adds space between the specified strings in the `txt` slice
Great for rendering a status line, or some kind of simple column set up
Adds space between the specified strings in the ` txt ` slice Great for rendering a status line or some kind of simple column set up
txt
&[&str]
space
usize