1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
pub mod f_print {
    use std::io::{self, Write};
    use std::thread;
    use std::time;

    // prints a timed message to the console with a new line
    pub fn println_timed(message: &str, time: time::Duration) {
        print_timed(message, time);
        new_line();
    }

    // prints a timed message to the console without a new line
    pub fn print_timed(message: &str, time: time::Duration) {
        for c in message.chars() {
            print!("{}", c);
            io::stdout().flush().unwrap();
            thread::sleep(time);
        }
    }

    // prints a message to the console with a new line
    pub fn println(message: &str) {
        print(message);
        new_line();
    }

    // prints a message to the console without a new line
    pub fn print(message: &str) {
        print!("{}", message);
        io::stdout().flush().unwrap();
    }

    // prints a blank line to the console
    pub fn new_line() {
        println!();
    }
}

pub mod f_list {
    use std::fmt;
    use std::io::{self, Write};

    pub struct List<T: fmt::Display> {
        items: Vec<T>,
    }

    impl<T: fmt::Display> List<T> {
        pub fn new() -> List<T> {
            List { items: Vec::new() }
        }

        pub fn from(items: Vec<T>) -> List<T> {
            List { items: items }
        }

        pub fn add_item(&mut self, item: T) {
            self.items.push(item);
        }

        pub fn display(&self) {
            for item in self.items.iter() {
                println!("{}", item);
            }
        }

        pub fn display_ordered(&self) {
            for (x, item) in self.items.iter().enumerate() {
                print!("[{}]: ", x + 1);
                io::stdout().flush().unwrap();
                println!("{}", item);
            }
        }
    }
}

pub mod f_input {
    use std::io;

    // get untrimmed input from console
    pub fn get_input() -> String {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        input
    }

    // get trimmed input from console
    pub fn get_input_trimmed() -> String {
        String::from(get_input().trim())
    }
}