pub fn build_line(line_length: &LineLength, character_generator: &impl Fn() -> char) -> Line {
    let mut string: String;
    let length: usize;
    match line_length {
        LineLength::Fixed(n) => {
            string = String::with_capacity(n + 1);
            length = *n + 1;
            for _ in 0..*n {
                string.push(character_generator());
            }
        }
        LineLength::Range(r) => {
            assert_ne!(r.start, r.end);

            // The length of the line, including newline.
            length = fastrand::usize(r.clone()) + 1;

            string = String::with_capacity(length);
            for _ in 0..(length - 1) {
                string.push(character_generator());
            }
        }
    }
    string.push('\n');

    Line { string, length }
}
/// Builds a line based on the provided parameters.
///
/// # Panics
///
/// Panics if given a `LineLength::Range(r)` where `r` is empty, e.g. `0..0` or `6..6`.
Builds a line based on the provided parameters.
Builds a line based on the provided parameters .
pub fn build_line(line_length: &LineLength, character_generator: &impl Fn() -> char) -> Line {
    let mut string: String;
    let length: usize;
    match line_length {
        LineLength::Fixed(n) => {
            string = String::with_capacity(n + 1);
            length = *n + 1;
            for _ in 0..*n {
                string.push(character_generator());
            }
        }
        LineLength::Range(r) => {
            assert_ne!(r.start, r.end);
            // The length of the line, including newline.
            length = fastrand::usize(r.clone()) + 1;
            string = String::with_capacity(length);
            for _ in 0..(length - 1) {
                string.push(character_generator());
            }
        }
    }
    string.push('\n');
    Line { string, length }
}
pub fn build_line ( line_length : & LineLength , character_generator : & impl Fn ( ) -> char ) -> Line { let mut string : String ; let length : usize ; match line_length { LineLength :: Fixed ( n ) => { string = String :: with_capacity ( n + 1 ) ; length = * n + 1 ; for _ in 0 .. * n { string . push ( character_generator ( ) ) ; } } LineLength :: Range ( r ) => { assert_ne ! ( r start r end ) ; // The length of the line, including newline. length = fastrand :: usize ( r . clone ( ) ) + 1 ; string = String :: with_capacity ( length ) ; for _ in 0 .. ( length - 1 ) { string . push ( character_generator ( ) ) ; } } } string . push ( '\n' ) ; Line { string , length } }
Builds a line based on the provided parameters.
Builds a line based on the provided parameters .
line_length
&LineLength
character_generator
&impl Fn() -> char
line_length
&LineLength
character_generator
&impl Fn() -> char
panics
Panics if given a `LineLength::Range(r)` where `r` is empty, e.g.
Panics if given a ` LineLength :: Range ( r ) ` where ` r ` is empty e . g .