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
use std::fs::read_to_string;

pub fn read_port_list(file_path: String) -> Result<Vec<u16>, String> {
    let data = read_to_string(file_path);
    let text = match data {
        Ok(content) => content,
        Err(_) => {
            return Err("Failed to read file".to_string());
        },
    };
    let port_list: Vec<&str> = text.trim().split("\n").collect();
    let mut ports: Vec<u16> = Vec::new();
    for port in port_list {
        match port.parse::<u16>() {
            Ok(p) => {
                ports.push(p);
            }
            Err(_) => {}
        }
    }
    Ok(ports)
}

pub fn read_word_list(file_path: String) -> Result<Vec<String>, String> {
    let data = read_to_string(file_path);
    let text = match data {
        Ok(content) => content,
        Err(_) => {
            return Err("Failed to read file".to_string());
        },
    };
    let word_list: Vec<&str> = text.trim().split("\n").collect();
    let mut words: Vec<String> = Vec::new();
    for word in word_list {
        words.push(word.to_string());
    }
    Ok(words)
}