wolf_graph_dot/
graph_attributes.rs

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