#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
pub struct DialectMetadata {
pub(crate) tags: DialectTags,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
pub struct DialectTags(Vec<String>);
impl DialectTags {
pub fn new(tags: &[impl AsRef<str>]) -> Self {
let tags = tags
.iter()
.map(|t| t.as_ref().to_string())
.collect::<Vec<_>>();
Self(tags)
}
pub fn tags(&self) -> &[String] {
self.0.as_slice()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn contains(&self, tag: impl AsRef<str>) -> bool {
self.0.iter().any(|t| t == tag.as_ref())
}
pub fn has_one_of(&self, tags: &Self) -> bool {
for present in self.0.iter() {
for requested in tags.0.iter() {
if present == requested {
return true;
}
}
}
false
}
pub fn extend(&mut self, tags: &DialectTags) {
for tag in tags.0.iter() {
if !self.0.contains(&tag) {
self.0.push(tag.to_string());
}
}
}
}
impl DialectMetadata {
#[inline(always)]
pub fn tags(&self) -> &[String] {
self.tags.tags()
}
#[inline(always)]
pub fn has_tag(&self, tag: impl AsRef<str>) -> bool {
self.tags.contains(tag)
}
#[inline(always)]
pub fn has_one_of_tags(&self, tags: &DialectTags) -> bool {
self.tags.has_one_of(tags)
}
}