pub struct IfcxFile {
pub header: IfcxHeader,
pub imports: Vec<ImportNode>,
pub schemas: IndexMap<String, IfcxSchema>,
pub data: Vec<IfcxNode>,
pub extra: Extra,
}Expand description
One IFCX file: a single layer of a dataset.
Fields§
§header: IfcxHeader§imports: Vec<ImportNode>§schemas: IndexMap<String, IfcxSchema>Attribute value descriptions, keyed by namespaced attribute id.
data: Vec<IfcxNode>Nodes in file order. Several nodes may share a path; layering merges them later.
extra: ExtraImplementations§
Source§impl IfcxFile
impl IfcxFile
pub fn from_json_str(input: &str) -> Result<Self, ReadError>
Sourcepub fn from_json_slice(input: &[u8]) -> Result<Self, ReadError>
pub fn from_json_slice(input: &[u8]) -> Result<Self, ReadError>
Examples found in repository?
65fn main() -> ExitCode {
66 let paths: Vec<String> = std::env::args().skip(1).collect();
67 if paths.is_empty() {
68 eprintln!("usage: compose-json <file.ifcx>...");
69 return ExitCode::FAILURE;
70 }
71 let mut data = Vec::new();
72 for path in &paths {
73 let file = std::fs::read(path)
74 .map_err(|e| e.to_string())
75 .and_then(|bytes| IfcxFile::from_json_slice(&bytes).map_err(|e| e.to_string()));
76 match file {
77 Ok(file) => data.extend(file.data),
78 Err(e) => {
79 eprintln!("{path}: {e}");
80 return ExitCode::FAILURE;
81 }
82 }
83 }
84
85 let stdout = std::io::stdout().lock();
86 let mut out = BufWriter::new(stdout);
87 let written = match compose(&flatten_owned(data)) {
88 Ok(composed) => serde_json::to_writer(&mut out, &Tree(&composed.root())),
89 Err(e) => {
90 let kind = match e {
91 ComposeError::Cycle { .. } => "cycle",
92 ComposeError::UnknownReference { .. } => "unknown-reference",
93 _ => "other",
94 };
95 let error = serde_json::json!({"error": {"kind": kind, "message": e.to_string()}});
96 serde_json::to_writer(&mut out, &error)
97 }
98 };
99 match written.map_err(std::io::Error::from).and_then(|()| {
100 out.write_all(b"\n")?;
101 out.flush()
102 }) {
103 Ok(()) => ExitCode::SUCCESS,
104 Err(e) => {
105 eprintln!("writing output: {e}");
106 ExitCode::FAILURE
107 }
108 }
109}Sourcepub fn from_json_reader(reader: impl Read) -> Result<Self, ReadError>
pub fn from_json_reader(reader: impl Read) -> Result<Self, ReadError>
Reads from a stream. Wrap unbuffered sources in a BufReader.
pub fn to_json_string(&self) -> Result<String, WriteError>
pub fn to_json_string_pretty(&self) -> Result<String, WriteError>
pub fn to_json_writer(&self, writer: impl Write) -> Result<(), WriteError>
Source§impl IfcxFile
impl IfcxFile
Sourcepub fn validate(&self) -> Result<(), ValidationReport>
pub fn validate(&self) -> Result<(), ValidationReport>
Checks every attribute in data against this file’s schemas.
Nodes sharing a path are merged first, later attribute values
replacing earlier ones, as upstream’s flattening does; a failure is
reported once per path, in order of each path’s first node. The
result equals validate_flat over flatten of
data, but no value is copied.
Imports are not resolved, so attributes whose schemas live only in an
imported file are reported as FailureKind::MissingSchema. To
validate a file with its imports, build its
LayerStack and call
LayerStack::validate.