wolf-graph-dot 0.1.0

Adds support for generating Graphviz DOT files from wolf-graph graphs.
Documentation
use std::fmt;

use crate::Color;

#[derive(Debug, Clone, PartialEq)]
pub struct GroupAttributes {
    pub label: Option<String>,
    pub color: Option<Color>,
}

impl GroupAttributes {
    pub fn new(label: Option<String>, color: Option<Color>) -> Self {
        Self { label, color }
    }

    pub fn attributes(&self, enclosed: bool) -> Option<String> {
        crate::details::encode::encode_attributes(
            &[
                ("label", self.label.as_ref().map(|s| s as &dyn ToString)),
                ("color", self.color.as_ref().map(|c| c as &dyn ToString)),
            ],
            enclosed,
        )
    }
}

impl Default for GroupAttributes {
    fn default() -> Self {
        Self::new(None, None)
    }
}

impl fmt::Display for GroupAttributes {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        if let Some(encoded) = self.attributes(true) {
            write!(f, "{}", encoded)
        } else {
            Ok(())
        }
    }
}