2020-03-22 21:10:50 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::prelude::*;
|
2019-09-18 09:12:50 +00:00
|
|
|
use std::path::PathBuf;
|
2020-03-22 21:10:50 +00:00
|
|
|
use anyhow::Result;
|
2019-09-17 15:33:35 +00:00
|
|
|
|
2020-03-22 21:10:50 +00:00
|
|
|
pub fn read_file(path: &PathBuf) -> Result<String> {
|
|
|
|
let mut file = File::open(path)?;
|
|
|
|
let mut contents = String::new();
|
|
|
|
file.read_to_string(&mut contents)?;
|
|
|
|
|
|
|
|
Ok(contents)
|
2019-09-17 15:33:35 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:10:50 +00:00
|
|
|
pub fn write_file(path: &PathBuf, ip: &str) -> Result<()> {
|
|
|
|
let mut file = File::create(path)?;
|
|
|
|
file.write_all(ip.as_bytes())?;
|
2019-09-17 15:33:35 +00:00
|
|
|
Ok(())
|
2019-09-18 09:12:50 +00:00
|
|
|
}
|