openbim_ifcx_geometry/
attributes.rs1use indexmap::IndexMap;
4use openbim_ifcx::{ComposedNode, FlatNode, IfcxNode};
5use serde_json::{Map, Value};
6
7pub trait Attributes {
18 fn raw_attribute(&self, id: &str) -> Option<&Value>;
20
21 fn attribute(&self, id: &str) -> Option<&Value> {
23 self.raw_attribute(id).filter(|value| !value.is_null())
24 }
25}
26
27impl Attributes for IndexMap<String, Value> {
28 fn raw_attribute(&self, id: &str) -> Option<&Value> {
29 self.get(id)
30 }
31}
32
33impl Attributes for Map<String, Value> {
34 fn raw_attribute(&self, id: &str) -> Option<&Value> {
35 self.get(id)
36 }
37}
38
39impl Attributes for IfcxNode {
40 fn raw_attribute(&self, id: &str) -> Option<&Value> {
41 self.attributes.as_ref()?.get(id)
42 }
43}
44
45impl Attributes for FlatNode {
46 fn raw_attribute(&self, id: &str) -> Option<&Value> {
47 self.attributes.get(id).map(|value| &**value)
48 }
49}
50
51impl Attributes for ComposedNode {
52 fn raw_attribute(&self, id: &str) -> Option<&Value> {
53 self.attributes.get(id).map(|value| &**value)
54 }
55}
56
57impl<T: Attributes + ?Sized> Attributes for &T {
58 fn raw_attribute(&self, id: &str) -> Option<&Value> {
59 (**self).raw_attribute(id)
60 }
61}