use cheetah_string::CheetahString;
use crate::common::attribute::Attribute;
use crate::common::attribute::AttributeBase;
#[derive(Debug, Clone)]
pub struct StringAttribute {
attribute: AttributeBase,
}
impl StringAttribute {
pub fn new(name: CheetahString, changeable: bool) -> Self {
Self {
attribute: AttributeBase::new(name, changeable),
}
}
}
impl Attribute for StringAttribute {
fn verify(&self, _value: &str) -> Result<(), String> {
Ok(())
}
fn name(&self) -> &CheetahString {
self.attribute.name()
}
fn is_changeable(&self) -> bool {
self.attribute.is_changeable()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn string_attribute_accepts_empty_and_non_empty_values() {
let attribute = StringAttribute::new(CheetahString::from_static_str("lite.bind.topic"), true);
assert!(attribute.verify("").is_ok());
assert!(attribute.verify("parent-topic").is_ok());
}
}