hostcraft-core 2.0.0

Core library for the hostcraft ecosystem — parsing, manipulation and file I/O for system hosts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use crate::host::{HostEntry, HostStatus};
use std::io::Write;

pub fn write_entries(entries: &[HostEntry], file: &mut impl Write) -> Result<(), std::io::Error> {
    for entry in entries {
        let line = match entry.status {
            HostStatus::Active => format!("{} {}\n", entry.ip, entry.name),
            HostStatus::Inactive => format!("# {} {}\n", entry.ip, entry.name),
        };
        file.write_all(line.as_bytes())?;
    }
    Ok(())
}