wolf_graph_dot/
group_attributes.rs1use std::fmt;
2
3use crate::Color;
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct GroupAttributes {
7 pub label: Option<String>,
8 pub color: Option<Color>,
9}
10
11impl GroupAttributes {
12 pub fn new(label: Option<String>, color: Option<Color>) -> Self {
13 Self { label, color }
14 }
15
16 pub fn attributes(&self, enclosed: bool) -> Option<String> {
17 crate::details::encode::encode_attributes(
18 &[
19 ("label", self.label.as_ref().map(|s| s as &dyn ToString)),
20 ("color", self.color.as_ref().map(|c| c as &dyn ToString)),
21 ],
22 enclosed,
23 )
24 }
25}
26
27impl Default for GroupAttributes {
28 fn default() -> Self {
29 Self::new(None, None)
30 }
31}
32
33impl fmt::Display for GroupAttributes {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 if let Some(encoded) = self.attributes(true) {
36 write!(f, "{}", encoded)
37 } else {
38 Ok(())
39 }
40 }
41}