1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
pub use std::fs::File;
pub use std::io::{BufRead, BufReader, BufWriter, Read, Seek, Write};
pub use std::path::{Path, PathBuf};
use anyhow::*;
pub fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
let s = std::fs::read_to_string(&path)
.with_context(|| format!("Failed to read string from file {:?}", path.as_ref()))?;
Ok(s)
}
pub fn write_to_file<P: AsRef<Path>>(path: P, content: &str) -> Result<()> {
std::fs::write(&path, content.as_bytes())
.with_context(|| format!("Failed to write to file {:?}", path.as_ref()))?;
Ok(())
}