pub(crate) mod json_trace;
pub(crate) mod model_checker_stdout;
pub(crate) mod tla_config_file;
pub(crate) mod tla_file;
pub(crate) mod tla_file_suite;
pub(crate) mod tla_trace;
use crate::Error;
use std::path::{Path, PathBuf};
use std::str;
pub fn try_write_to_dir<'a, P: AsRef<Path>, C>(dir: P, collection: C) -> Result<(), Error>
where
C: IntoIterator<Item = Box<&'a dyn ArtifactSaver>>,
{
for artifact in collection {
artifact.try_write_to_dir(dir.as_ref())?;
}
Ok(())
}
pub trait ArtifactCreator
where
Self: Sized,
{
fn from_string(s: &str) -> Result<Self, Error>;
fn try_read_from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
let file_content = crate::util::try_read_file_contents(path)?;
Self::from_string(&file_content)
}
}
pub trait Artifact {
fn as_string(&self) -> String;
fn try_write_to_file(&self, path: &Path) -> Result<(), Error> {
Ok(std::fs::write(path, self.as_string())?)
}
}
pub trait ArtifactSaver: Artifact {
fn filename(&self) -> String;
fn try_write_to_dir(&self, path: &Path) -> Result<PathBuf, Error> {
let full_path = path.join(self.filename());
std::fs::write(&full_path, self.as_string())?;
Ok(full_path)
}
}
pub use json_trace::JsonTrace;
pub use model_checker_stdout::ModelCheckerStdout;
pub use tla_config_file::TlaConfigFile;
pub use tla_file::TlaFile;
pub use tla_file_suite::TlaFileSuite;
pub use tla_trace::TlaTrace;