Skip to main content

ifc_material/material/
definition.rs

1//! Borrowed `IfcMaterial` identity.
2
3use crate::view::{borrowed_entity, optional_text, required_text, MaterialView};
4use crate::MaterialResult;
5
6borrowed_entity!(Material, "IFCMATERIAL");
7
8impl<'m> Material<'m> {
9    /// `IfcMaterial.Name`. Required; a malformed record is an error, not
10    /// an absent value. Declared by every release.
11    pub fn name(self) -> MaterialResult<&'m str> {
12        required_text(
13            "IFCMATERIAL",
14            self.id(),
15            self.entity(),
16            self.slot("Name")?,
17            "Name",
18        )
19    }
20
21    /// `IfcMaterial.Description`, if given.
22    ///
23    /// # Errors
24    ///
25    /// [`crate::MaterialError::NotInSchema`] for IFC2X3, whose `IfcMaterial`
26    /// declares `Name` only.
27    pub fn description(self) -> MaterialResult<Option<&'m str>> {
28        optional_text(
29            "IFCMATERIAL",
30            self.id(),
31            self.entity(),
32            self.slot("Description")?,
33            "Description",
34        )
35    }
36
37    /// `IfcMaterial.Category`, if given.
38    ///
39    /// # Errors
40    ///
41    /// [`crate::MaterialError::NotInSchema`] for IFC2X3, whose `IfcMaterial`
42    /// declares `Name` only.
43    pub fn category(self) -> MaterialResult<Option<&'m str>> {
44        optional_text(
45            "IFCMATERIAL",
46            self.id(),
47            self.entity(),
48            self.slot("Category")?,
49            "Category",
50        )
51    }
52}
53
54impl<'m> MaterialView<'m> {
55    /// Iterates every `IfcMaterial` instance in the model.
56    pub fn materials(self) -> impl Iterator<Item = Material<'m>> + 'm {
57        let release = self.release();
58        self.model()
59            .of_type("IFCMATERIAL")
60            .map(move |(id, entity)| Material::from_known(id, entity, release))
61    }
62}