19 lines
429 B
Rust
19 lines
429 B
Rust
use std::fs::File;
|
|
use std::io::prelude::*;
|
|
use std::path::PathBuf;
|
|
use anyhow::Result;
|
|
|
|
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)
|
|
}
|
|
|
|
pub fn write_file(path: &PathBuf, ip: &str) -> Result<()> {
|
|
let mut file = File::create(path)?;
|
|
file.write_all(ip.as_bytes())?;
|
|
Ok(())
|
|
}
|