ligen_ir/macro_attributes/attributes/attribute/
mod.rs

1//! Attribute enumeration.
2
3pub mod named;
4pub mod group;
5
6#[cfg(any(test, feature = "mocks"))]
7pub mod mock;
8
9use std::fmt::{Display, Formatter};
10use crate::prelude::*;
11use crate::Literal;
12
13pub use group::*;
14
15pub use named::*;
16
17/// Attribute enueration.
18#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
19pub enum Attribute {
20    /// Literal Variant
21    Literal(Literal),
22    /// Named Variant
23    Named(Named),
24    /// Group Variant
25    Group(Group),
26}
27
28impl From<Literal> for Attribute {
29    fn from(literal: Literal) -> Self {
30        Self::Literal(literal)
31    }
32}
33
34impl From<Named> for Attribute {
35    fn from(named: Named) -> Self {
36        Self::Named(named)
37    }
38}
39
40impl From<Group> for Attribute {
41    fn from(group: Group) -> Self {
42        Self::Group(group)
43    }
44}
45
46impl Default for Attribute {
47    fn default() -> Self {
48        Self::Literal(Literal::default())
49    }
50}
51
52impl Display for Attribute {
53    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
54        match self {
55            Attribute::Literal(literal) => write!(f, "{}", literal),
56            Attribute::Named(named) => write!(f, "{}", named),
57            Attribute::Group(group) => write!(f, "{}", group),
58        }
59    }
60}