load_hosts

Function load_hosts 

Source
pub fn load_hosts(path: &Path) -> Result<HostTable>
Expand description

Loads a host table from the given filename.

If an error is encountered in opening the file or reading its contents or if the file is malformed, the error is returned.

Examples found in repository?
examples/host_table.rs (line 9)
3fn main() {
4    let path = host_file();
5
6    println!("Loading host table from {}", path.display());
7    println!("");
8
9    let table = match load_hosts(&path) {
10        Ok(t) => t,
11        Err(e) => {
12            println!("Failed to load host table: {}", e);
13            return;
14        }
15    };
16
17    for host in &table.hosts {
18        println!("  {:<20} points to {}", host.name, host.address);
19
20        for alias in &host.aliases {
21            println!("  {:<20} points to {}", alias, host.address);
22        }
23    }
24}