ligen_ir/macro_attributes/attributes/attribute/
group.rs

1use std::fmt::{Display, Formatter};
2
3use crate::prelude::*;
4
5use crate::{Path, Identifier, Attributes};
6
7/// Attributes group.
8#[derive(Default, Debug, PartialEq, Clone, Serialize, Deserialize)]
9pub struct Group {
10    /// Path of the group.
11    pub path: Path,
12    /// Attributes of the group.
13    pub attributes: Attributes,
14}
15
16impl Group {
17    pub fn new<I: Into<Path>, A: Into<Attributes>>(path: I, attributes: A) -> Self {
18        let path = path.into();
19        let attributes = attributes.into();
20        Self { path, attributes }
21    }
22}
23
24impl From<&str> for Group {
25    fn from(value: &str) -> Self {
26        Self { path: value.into(), ..Default::default() }
27    }
28}
29
30impl From<Path> for Group {
31    fn from(path: Path) -> Self {
32        Self { path, ..Default::default() }
33    }
34}
35
36impl From<Identifier> for Group {
37    fn from(identifier: Identifier) -> Self {
38        Path::from(identifier).into()
39    }
40}
41
42impl Display for Group {
43    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
44        write!(f, "{}({})", self.path, self.attributes)
45    }
46}