2018-12-22 16:09:22 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Error;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
2019-01-12 14:39:20 +00:00
|
|
|
|
2018-12-22 16:09:22 +00:00
|
|
|
use tempfile::tempdir;
|
|
|
|
use tempfile::TempDir;
|
|
|
|
|
|
|
|
pub struct Source {
|
|
|
|
directory: TempDir,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Source {
|
|
|
|
pub fn new() -> Result<Self, Error> {
|
|
|
|
Ok(Self { directory: tempdir()? })
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn write_text_to_file(&self, filename: &str, text: &str) -> Result<(), Error> {
|
|
|
|
Ok(File::create(self.directory.path().join(filename))?.write_all(text.as_bytes())?)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn path(&self) -> &Path {
|
|
|
|
self.directory.path()
|
|
|
|
}
|
|
|
|
}
|