remodel_core/format/
mod.rs1use serde::{Deserialize, Serialize};
9
10use crate::error::Result;
11use crate::models::conceptual::ConceptualModel;
12use crate::models::logical::LogicalModel;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct RemodelFile {
17 pub writer: String,
19 pub conceptual: ConceptualModel,
21 #[serde(skip_serializing_if = "Option::is_none", default)]
23 pub logical: Option<LogicalModel>,
24}
25
26impl RemodelFile {
27 pub fn new(conceptual: ConceptualModel) -> Self {
30 Self {
31 writer: format!("remodel-core/{}", crate::VERSION),
32 conceptual,
33 logical: None,
34 }
35 }
36
37 pub fn to_json(&self) -> Result<String> {
39 serde_json::to_string_pretty(self)
40 .map_err(|e| crate::Error::Internal(format!("serialize: {e}")))
41 }
42
43 pub fn from_json(s: &str) -> Result<Self> {
45 serde_json::from_str(s).map_err(|e| crate::Error::Internal(format!("parse: {e}")))
46 }
47}