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
34
35
36
37
38
use config::PathType;
use std::path::PathBuf;
pub struct AlteredToml(PathType, String, PathBuf);
#[allow(dead_code)]
impl AlteredToml {
pub fn new(search: &str, replace: &str, p_type: PathType, replace_path: PathBuf) -> Self {
let path = p_type.get_path(&replace_path);
let data = std::fs::read_to_string(&path).unwrap();
let new_str = data.replace(search, replace);
std::fs::write(&path, new_str).unwrap();
AlteredToml(p_type, data, replace_path)
}
}
impl Drop for AlteredToml {
fn drop(&mut self) {
let path = self.0.get_path(&self.2);
std::fs::write(&path, &self.1).unwrap_or_else(|e| {
panic!(
"Unable to reset file {} after test due to error {}",
path.to_string_lossy(),
e
)
})
}
}