rocketmq_model/common/attribute/
string_attribute.rs1use cheetah_string::CheetahString;
16
17use crate::common::attribute::Attribute;
18use crate::common::attribute::AttributeBase;
19
20#[derive(Debug, Clone)]
21pub struct StringAttribute {
22 attribute: AttributeBase,
23}
24
25impl StringAttribute {
26 pub fn new(name: CheetahString, changeable: bool) -> Self {
27 Self {
28 attribute: AttributeBase::new(name, changeable),
29 }
30 }
31}
32
33impl Attribute for StringAttribute {
34 fn verify(&self, _value: &str) -> Result<(), String> {
35 Ok(())
36 }
37
38 fn name(&self) -> &CheetahString {
39 self.attribute.name()
40 }
41
42 fn is_changeable(&self) -> bool {
43 self.attribute.is_changeable()
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn string_attribute_accepts_empty_and_non_empty_values() {
53 let attribute = StringAttribute::new(CheetahString::from_static_str("lite.bind.topic"), true);
54
55 assert!(attribute.verify("").is_ok());
56 assert!(attribute.verify("parent-topic").is_ok());
57 }
58}