20 lines
445 B
Rust
20 lines
445 B
Rust
use failure::Error;
|
|
use std::fs::File;
|
|
use std::io::prelude::*;
|
|
use std::path::PathBuf;
|
|
|
|
pub fn read_cache_file(path: &PathBuf) -> Result<String, Error> {
|
|
let mut file = File::open(&path)?;
|
|
let mut s = String::new();
|
|
file.read_to_string(&mut s)?;
|
|
|
|
Ok(s.clone())
|
|
}
|
|
|
|
pub fn write_cache_file(path: &PathBuf, ip: &str) -> Result<(), Error> {
|
|
let mut file = File::create(&path)?;
|
|
file.write_all(ip.as_bytes())?;
|
|
|
|
Ok(())
|
|
}
|