1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: Apache-2.0
//! A CAD document together with its decode origin.
use crate::{CadIr, DecodeReport, SourceFidelity};
/// A neutral document and the source information available for later export.
#[derive(Debug, Clone, PartialEq)]
pub struct DocumentArtifact {
/// The format-neutral document.
pub ir: CadIr,
/// Whether the document came from neutral JSON or a native decoder.
pub origin: DocumentOrigin,
}
/// Source information attached to a loaded document.
#[derive(Debug, Clone, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum DocumentOrigin {
/// The document was loaded without native decode metadata.
Neutral,
/// The document was produced by a native decoder.
Decoded {
/// What the decoder transferred and omitted.
report: DecodeReport,
/// Decode-time annotations and retained native records.
fidelity: SourceFidelity,
},
}
impl DocumentArtifact {
/// Creates an artifact from a neutral document.
pub const fn neutral(ir: CadIr) -> Self {
Self {
ir,
origin: DocumentOrigin::Neutral,
}
}
/// Creates an artifact from a native decode result.
pub fn decoded(result: crate::DecodeResult) -> Self {
Self {
ir: result.ir,
origin: DocumentOrigin::Decoded {
report: result.report,
fidelity: result.source_fidelity,
},
}
}
/// Returns the native decode report, when this artifact has decoded origin.
pub const fn decode_report(&self) -> Option<&DecodeReport> {
match &self.origin {
DocumentOrigin::Neutral => None,
DocumentOrigin::Decoded { report, .. } => Some(report),
}
}
/// Returns source fidelity, when this artifact has decoded origin.
pub const fn fidelity(&self) -> Option<&SourceFidelity> {
match &self.origin {
DocumentOrigin::Neutral => None,
DocumentOrigin::Decoded { fidelity, .. } => Some(fidelity),
}
}
}