dbc_rs/attribute/
impls.rs1use super::{
4 AttributeDefinition, AttributeObjectType, AttributeValue, AttributeValueType, EnumValues,
5};
6
7impl AttributeObjectType {
12 #[inline]
16 #[must_use]
17 pub fn as_str(&self) -> &'static str {
18 match self {
19 Self::Network => "",
20 Self::Node => "BU_",
21 Self::Message => "BO_",
22 Self::Signal => "SG_",
23 }
24 }
25
26 #[inline]
28 #[must_use]
29 pub fn is_network(&self) -> bool {
30 matches!(self, Self::Network)
31 }
32
33 #[inline]
35 #[must_use]
36 pub fn is_node(&self) -> bool {
37 matches!(self, Self::Node)
38 }
39
40 #[inline]
42 #[must_use]
43 pub fn is_message(&self) -> bool {
44 matches!(self, Self::Message)
45 }
46
47 #[inline]
49 #[must_use]
50 pub fn is_signal(&self) -> bool {
51 matches!(self, Self::Signal)
52 }
53}
54
55impl AttributeValueType {
60 #[inline]
62 #[must_use]
63 pub fn is_int(&self) -> bool {
64 matches!(self, Self::Int { .. } | Self::Hex { .. })
65 }
66
67 #[inline]
69 #[must_use]
70 pub fn is_float(&self) -> bool {
71 matches!(self, Self::Float { .. })
72 }
73
74 #[inline]
76 #[must_use]
77 pub fn is_string(&self) -> bool {
78 matches!(self, Self::String)
79 }
80
81 #[inline]
83 #[must_use]
84 pub fn is_enum(&self) -> bool {
85 matches!(self, Self::Enum { .. })
86 }
87
88 #[inline]
90 #[must_use]
91 pub fn enum_values(&self) -> Option<&EnumValues> {
92 match self {
93 Self::Enum { values } => Some(values),
94 _ => None,
95 }
96 }
97
98 #[inline]
100 #[must_use]
101 pub fn int_range(&self) -> Option<(i64, i64)> {
102 match self {
103 Self::Int { min, max } | Self::Hex { min, max } => Some((*min, *max)),
104 _ => None,
105 }
106 }
107
108 #[inline]
110 #[must_use]
111 pub fn float_range(&self) -> Option<(f64, f64)> {
112 match self {
113 Self::Float { min, max } => Some((*min, *max)),
114 _ => None,
115 }
116 }
117}
118
119impl AttributeValue {
124 #[inline]
126 #[must_use]
127 pub fn as_int(&self) -> Option<i64> {
128 match self {
129 Self::Int(v) => Some(*v),
130 _ => None,
131 }
132 }
133
134 #[inline]
136 #[must_use]
137 pub fn as_float(&self) -> Option<f64> {
138 match self {
139 Self::Float(v) => Some(*v),
140 _ => None,
141 }
142 }
143
144 #[inline]
148 #[must_use]
149 pub fn as_string(&self) -> Option<&str> {
150 match self {
151 Self::String(s) => Some(s.as_str()),
152 _ => None,
153 }
154 }
155
156 #[inline]
158 #[must_use]
159 pub fn is_int(&self) -> bool {
160 matches!(self, Self::Int(_))
161 }
162
163 #[inline]
165 #[must_use]
166 pub fn is_float(&self) -> bool {
167 matches!(self, Self::Float(_))
168 }
169
170 #[inline]
172 #[must_use]
173 pub fn is_string(&self) -> bool {
174 matches!(self, Self::String(_))
175 }
176}
177
178impl AttributeDefinition {
183 #[inline]
185 #[must_use]
186 pub fn name(&self) -> &str {
187 self.name.as_str()
188 }
189
190 #[inline]
192 #[must_use]
193 pub fn object_type(&self) -> AttributeObjectType {
194 self.object_type
195 }
196
197 #[inline]
199 #[must_use]
200 pub fn value_type(&self) -> &AttributeValueType {
201 &self.value_type
202 }
203}