use std::fs; pub struct Config { pub query: String, // query: String, pub filename: String, // filename: String, pub contents: String, // contents: String, } impl Config { pub fn new(query: String, filename: String, contents: String) -> Config { Config { query, filename, contents, } } // write contents to filename pub fn setup(&self) -> Result { let contents = self.contents.clone(); let query = self.query.clone(); fs::write(&self.filename, &contents).map_err(|e| e.to_string())?; Ok(Config::new(query, self.filename.to_string(), contents)) } // delete file pub fn teardown(&self) -> Result<(), String> { fs::remove_file(&self.filename).map_err(|e| e.to_string())?; Ok(()) } }