use std::fs;
use std::pin::Pin;
use dir_structure::prelude::*;
use dir_structure::vfs::fs_vfs::FsVfs;
mod example_dirs;
#[derive(dir_structure::DirStructure)]
struct Dir {
#[dir_structure(path = "input.txt")]
input: String,
#[dir_structure(path = "output.txt")]
output: String,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = example_dirs::get_example_dir_path("reading");
let vfs = FsVfs;
let dir = Dir::read_from(path.as_ref(), Pin::new(&vfs))?;
let dir = vfs.read_typed::<Dir>(&path)?;
println!("input: {}", dir.input);
println!("output: {}", dir.output);
let write_path = example_dirs::get_example_dir_path("temp_writing");
dir.write_to(write_path.as_ref(), Pin::new(&vfs))?;
vfs.write_typed(&write_path, &dir)?;
assert_eq!(fs::read_to_string(write_path.join("input.txt"))?, dir.input);
assert_eq!(
fs::read_to_string(write_path.join("output.txt"))?,
dir.output
);
Ok(())
}