ifc_schema/types.rs
1//! Defined types, enumerations, and selects used by IFC schemas.
2
3/// Structural shape of a `TYPE` declaration.
4///
5/// `#[non_exhaustive]`: a match needs a wildcard arm, so recognising a
6/// further declaration form later is not a breaking change.
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum TypeKind {
10 /// Alias or other right-hand-side syntax retained as text.
11 Defined(String),
12 /// `ENUMERATION OF` member names.
13 Enumeration(Vec<String>),
14 /// `SELECT` member type names.
15 Select(Vec<String>),
16}
17
18/// One `TYPE` declaration.
19///
20/// `#[non_exhaustive]`: build one with [`TypeDef::new`].
21#[derive(Debug, Clone, PartialEq, Eq)]
22#[non_exhaustive]
23pub struct TypeDef {
24 /// Declared type name.
25 pub name: String,
26 /// Structurally recognized declaration kind.
27 pub kind: TypeKind,
28}
29
30impl TypeDef {
31 /// Creates a type declaration.
32 #[must_use]
33 pub fn new(name: impl Into<String>, kind: TypeKind) -> Self {
34 Self {
35 name: name.into(),
36 kind,
37 }
38 }
39
40 /// Returns whether this declaration aliases another type.
41 #[must_use]
42 pub const fn is_defined(&self) -> bool {
43 matches!(self.kind, TypeKind::Defined(_))
44 }
45}