hostcraft_core/file/
mod.rs1mod utils;
2use crate::file::utils::write_entries;
3use crate::host::HostEntry;
4use std::{
5 fs::File,
6 io::{self, BufRead},
7 path::Path,
8};
9
10pub fn read_file<P>(file_path: P) -> io::Result<io::Lines<io::BufReader<File>>>
11where
12 P: AsRef<Path>,
13{
14 let file = File::open(file_path)?;
15 Ok(io::BufReader::new(file).lines())
16}
17
18pub fn write_file<P>(file_path: P, entries: &[HostEntry]) -> io::Result<()>
19where
20 P: AsRef<Path>,
21{
22 let mut file = File::create(file_path)?;
23 write_entries(entries, &mut file)?;
24 Ok(())
25}