#[allow(unused_imports)]
use super::*;
use crate::attribute::{
AttributeDefinition, AttributeDefinitions as AttrDefsVec, AttributeObjectType,
};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AttributeDefinitionsMap {
definitions: AttrDefsVec,
}
impl AttributeDefinitionsMap {
#[allow(dead_code)]
pub(crate) fn new() -> Self {
Self {
definitions: AttrDefsVec::new(),
}
}
pub(crate) fn from_vec(definitions: AttrDefsVec) -> Self {
Self { definitions }
}
#[inline]
#[must_use = "iterator is lazy and does nothing unless consumed"]
pub fn iter(&self) -> impl Iterator<Item = &AttributeDefinition> {
self.definitions.as_slice().iter()
}
#[inline]
#[must_use = "return value should be used"]
pub fn len(&self) -> usize {
self.definitions.len()
}
#[inline]
#[must_use = "return value should be used"]
pub fn is_empty(&self) -> bool {
self.definitions.is_empty()
}
#[inline]
#[must_use = "return value should be used"]
pub fn get(&self, name: &str) -> Option<&AttributeDefinition> {
self.definitions.as_slice().iter().find(|def| def.name() == name)
}
#[inline]
#[must_use = "return value should be used"]
pub fn get_for_type(
&self,
name: &str,
object_type: AttributeObjectType,
) -> Option<&AttributeDefinition> {
self.definitions
.as_slice()
.iter()
.find(|def| def.name() == name && def.object_type() == object_type)
}
}