use super::{
AttributeDefinition, AttributeObjectType, AttributeValue, AttributeValueType, EnumValues,
};
impl AttributeObjectType {
#[inline]
#[must_use]
pub fn as_str(&self) -> &'static str {
match self {
Self::Network => "",
Self::Node => "BU_",
Self::Message => "BO_",
Self::Signal => "SG_",
}
}
#[inline]
#[must_use]
pub fn is_network(&self) -> bool {
matches!(self, Self::Network)
}
#[inline]
#[must_use]
pub fn is_node(&self) -> bool {
matches!(self, Self::Node)
}
#[inline]
#[must_use]
pub fn is_message(&self) -> bool {
matches!(self, Self::Message)
}
#[inline]
#[must_use]
pub fn is_signal(&self) -> bool {
matches!(self, Self::Signal)
}
}
impl AttributeValueType {
#[inline]
#[must_use]
pub fn is_int(&self) -> bool {
matches!(self, Self::Int { .. } | Self::Hex { .. })
}
#[inline]
#[must_use]
pub fn is_float(&self) -> bool {
matches!(self, Self::Float { .. })
}
#[inline]
#[must_use]
pub fn is_string(&self) -> bool {
matches!(self, Self::String)
}
#[inline]
#[must_use]
pub fn is_enum(&self) -> bool {
matches!(self, Self::Enum { .. })
}
#[inline]
#[must_use]
pub fn enum_values(&self) -> Option<&EnumValues> {
match self {
Self::Enum { values } => Some(values),
_ => None,
}
}
#[inline]
#[must_use]
pub fn int_range(&self) -> Option<(i64, i64)> {
match self {
Self::Int { min, max } | Self::Hex { min, max } => Some((*min, *max)),
_ => None,
}
}
#[inline]
#[must_use]
pub fn float_range(&self) -> Option<(f64, f64)> {
match self {
Self::Float { min, max } => Some((*min, *max)),
_ => None,
}
}
}
impl AttributeValue {
#[inline]
#[must_use]
pub fn as_int(&self) -> Option<i64> {
match self {
Self::Int(v) => Some(*v),
_ => None,
}
}
#[inline]
#[must_use]
pub fn as_float(&self) -> Option<f64> {
match self {
Self::Float(v) => Some(*v),
_ => None,
}
}
#[inline]
#[must_use]
pub fn as_string(&self) -> Option<&str> {
match self {
Self::String(s) => Some(s.as_str()),
_ => None,
}
}
#[inline]
#[must_use]
pub fn is_int(&self) -> bool {
matches!(self, Self::Int(_))
}
#[inline]
#[must_use]
pub fn is_float(&self) -> bool {
matches!(self, Self::Float(_))
}
#[inline]
#[must_use]
pub fn is_string(&self) -> bool {
matches!(self, Self::String(_))
}
}
impl AttributeDefinition {
#[inline]
#[must_use]
pub fn name(&self) -> &str {
self.name.as_str()
}
#[inline]
#[must_use]
pub fn object_type(&self) -> AttributeObjectType {
self.object_type
}
#[inline]
#[must_use]
pub fn value_type(&self) -> &AttributeValueType {
&self.value_type
}
}