#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AttributeValue(String);
impl AttributeValue {
pub fn new(value: impl Into<String>) -> Self {
Self(value.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Attribute {
name: String,
name_format: Option<String>,
values: Vec<AttributeValue>,
}
impl Attribute {
pub fn new(
name: impl Into<String>,
name_format: Option<String>,
values: Vec<AttributeValue>,
) -> Self {
Self {
name: name.into(),
name_format,
values,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn name_format(&self) -> Option<&str> {
self.name_format.as_deref()
}
pub fn values(&self) -> &[AttributeValue] {
&self.values
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Attributes(Vec<Attribute>);
impl Attributes {
pub fn new(values: Vec<Attribute>) -> Self {
Self(values)
}
pub fn as_slice(&self) -> &[Attribute] {
&self.0
}
pub fn get(&self, name: &str) -> Option<&Attribute> {
self.0.iter().find(|attribute| attribute.name() == name)
}
}
impl IntoIterator for Attributes {
type Item = Attribute;
type IntoIter = std::vec::IntoIter<Attribute>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}