microcad_lang/model/attribute/
export_command.rs1use crate::{
7 builtin::{ExportError, Exporter},
8 model::Model,
9 value::Value,
10};
11
12#[derive(Clone)]
14pub struct ExportCommand {
15 pub filename: std::path::PathBuf,
17 pub exporter: std::rc::Rc<dyn Exporter>,
19}
20
21impl ExportCommand {
22 pub fn export(&self, model: &Model) -> Result<Value, ExportError> {
24 self.exporter.export(model, &self.filename)
25 }
26}
27
28impl From<ExportCommand> for Value {
29 fn from(export_attribute: ExportCommand) -> Self {
30 crate::create_tuple_value!(
31 filename = Value::String(String::from(
32 export_attribute.filename.to_str().expect("PathBuf"),
33 )),
34 id = Value::String(export_attribute.exporter.id().to_string())
35 )
36 }
37}
38
39impl std::fmt::Debug for ExportCommand {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 write!(
42 f,
43 "Export: {id:?} => {filename}",
44 id = self.exporter.id(),
45 filename = self.filename.display()
46 )
47 }
48}
49
50impl std::fmt::Display for ExportCommand {
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 write!(
53 f,
54 "\"{filename}\" with exporter `{id}`",
55 filename = self.filename.display(),
56 id = self.exporter.id(),
57 )
58 }
59}