pub type AttributeValuePrinter = dyn Fn(&str, &str, &str, usize) -> String;
Expand description

A function which can be passed to the PrinterContext to provide custom printing for attribute values.

§Example:

use dot_generator::*;
use dot_structures::*;
use graphviz_rust::printer::{AttributeValuePrinter, DotPrinter, PrinterContext};
fn attr_formatter_test() {
    let mut ctx = PrinterContext::default();
    let formatter: Box<AttributeValuePrinter> =
        Box::new(|value, _line_sep, _indent, _indent_step| format!(r#""**{}**""#, value.trim_matches('"')));
    let g = graph!(di id!("attr_formatting");
         node!("abc";attr!("custom",esc "Custom Text")),
         edge!(node_id!("a") => node_id!("b"))
    );
    assert_eq!(
        "digraph attr_formatting {\n  abc[custom=\"**Custom Text**\"]\n  a -> b\n}",
        g.print(
            ctx.with_node_mult_attr_s_l()
                .with_attribute_formatter(id!("custom"), formatter)
        )
    );
}