1use serde::Serialize;
2use std::{fs, io, path::PathBuf};
3
4pub struct Info {
7 info_path: PathBuf,
9}
10
11impl Info {
12 pub fn new(info_path: PathBuf) -> Info {
13 Info { info_path }
14 }
15
16 pub fn write_to_json_file<T: Serialize>(&self, path: String, data: T) -> io::Result<()> {
17 let path = self.info_path.join(path);
18 let json = serde_json::to_string(&data).map_err(|err| {
19 io::Error::new(
20 io::ErrorKind::Other,
21 format!("Failed to serialize data: {}", err),
22 )
23 })?;
24
25 fs::write(path, json)
26 }
27}