use crate::{
builtin::{ExportError, Exporter},
model::Model,
value::Value,
};
#[derive(Clone)]
pub struct ExportCommand {
pub filename: std::path::PathBuf,
pub exporter: std::rc::Rc<dyn Exporter>,
}
impl ExportCommand {
pub fn export(&self, model: &Model) -> Result<Value, ExportError> {
self.exporter.export(model, &self.filename)
}
}
impl From<ExportCommand> for Value {
fn from(export_attribute: ExportCommand) -> Self {
crate::create_tuple_value!(
filename = Value::String(String::from(
export_attribute.filename.to_str().expect("PathBuf"),
)),
id = Value::String(export_attribute.exporter.id().to_string())
)
}
}
impl std::fmt::Debug for ExportCommand {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Export: {id:?} => {filename}",
id = self.exporter.id(),
filename = self.filename.display()
)
}
}
impl std::fmt::Display for ExportCommand {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"\"{filename}\" with exporter `{id}`",
filename = self.filename.display(),
id = self.exporter.id(),
)
}
}