xenon_codegen/
attribute.rs

1use crate::identifier::Identifier;
2
3/// An attribute applied to it's owner
4#[derive(Clone, Default)]
5pub struct Attribute {
6    /// The name of the attribute
7    pub name: Identifier,
8    /// The value of the attribute, if any
9    pub value: Option<Identifier>
10}
11impl Attribute {
12    /// Create a new, valid instance of Attribute
13    pub fn new(name: Identifier) -> Attribute {
14        return Attribute {
15            name,
16            value: None
17        };
18    }
19
20    /// Check if the instance of Attribute is valid
21    pub fn is_valid(&self) -> bool {
22        if !self.name.is_valid() {
23            return false;
24        }
25        match self.value.as_ref() {
26            Some(i) => {
27                return i.is_valid();
28            }
29            None => {
30                return true;
31            }
32        }
33    }
34}