wolf-graph-dot 0.1.0

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

use crate::details::encode::encode_attributes;

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

impl GraphAttributes {
    pub fn new(label: Option<String>) -> Self {
        Self { label }
    }

    pub fn attributes(&self) -> Option<String> {
        encode_attributes(&[
            ("label", self.label.as_ref().map(|s| s as &dyn ToString))
        ], true)
    }
}

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

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