rustcow 0.1.0

Cowsay, in Rust, inspired by Python's cowpy.
Documentation
pub mod chars;
pub use chars::COW;

pub fn create_chatbox<T: AsRef<str>>(input: T) -> String {
    let mut input: String = input.as_ref().into();
    let mut output = String::new();

    // Replace newlines with spaces.
    input = input.replace("\n", " ");
    // Remove whitespace, keep spaces.
    input.retain(|x| !x.is_whitespace() || x == ' ');

    let length = input.chars().count();
    let num_lines = (length as f64 / 50.0).ceil() as usize;

    // Top border
    output += &format!(" {}", "_".repeat(50 + 2));
    output += "\n";

    // User content
    match num_lines {
        1 => {
            output += &format!("< {:50} >", &input);
            output += "\n";
        }
        2 => {
            let first_line: String = input.chars().take(50).collect();
            let second_line: String = input.chars().skip(50).collect();
            output += &format!(r"/ {} \", &first_line);
            output += "\n";
            output += &format!(r"\ {:50} /", &second_line);
            output += "\n";
        }
        _ => {
            let first_line: String = input.chars().take(50).collect();
            let last_line: String = input.chars().skip(50 * (num_lines - 1)).collect();
            output += &format!(r"/ {} \", &first_line);
            output += "\n";
            for n in 0..num_lines - 2 {
                let line: String = input.chars().skip(50 * (n + 1)).take(50).collect();
                output += &format!("| {} |", &line);
                output += "\n";
            }
            output += &format!(r"\ {:50} /", &last_line);
            output += "\n";
        }
    }

    // Bottom border
    output += &format!(" {}", "-".repeat(50 + 2));

    output
}