pub struct D2Describer {
pub simple_type_name: bool,
pub show_context_in_node: bool,
pub show_description: bool,
pub show_externals: bool,
}d2describer only.Expand description
A configurable formatter for converting Description structures into
D2 graph syntax.
§Examples
use node_flow::describe::{Description, D2Describer};
use node_flow::node::{Node, NodeOutput};
use node_flow::flows::FnFlow;
let flow = ExampleNode;
let some_description = flow.describe();
let mut describer = D2Describer::new();
describer.modify(|cfg| {
cfg.show_description = true;
cfg.show_externals = true;
});
let d2_code = describer.format(&some_description);
println!("{}", d2_code);
// Output could be fed to a D2 renderer for visualization.Fields§
§simple_type_name: boolWhether to display simplified type names instead of full paths.
When enabled, types like my_crate::nodes::ExampleNode become ExampleNode.
This makes diagrams more readable, especially for complex flows.
show_context_in_node: boolWhether to display the node context type inside each node.
When enabled, context will be added to node’s description.
show_description: boolWhether to include the node’s description.
When enabled, description will be included in the node.
show_externals: boolWhether to include information about external resources.
When enabled, external resources will be included in the node.
Implementations§
Source§impl D2Describer
impl D2Describer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new D2Describer using default configuration.
Default settings:
simple_type_name:trueshow_context_in_node:falseshow_description:falseshow_externals:false
Sourcepub fn modify(&mut self, func: impl FnOnce(&mut Self)) -> &mut Self
pub fn modify(&mut self, func: impl FnOnce(&mut Self)) -> &mut Self
Allows modification of the configuration using a closure.
§Examples
let mut describer = D2Describer::new();
describer.modify(|cfg| {
cfg.show_description = true;
cfg.show_externals = true;
});Sourcepub fn format(&self, desc: &Description) -> String
pub fn format(&self, desc: &Description) -> String
Formats a Description into a D2 diagram text representation.
The resulting string can be passed directly to the D2 CLI or rendered using the D2 playground.
§Parameters
desc: TheDescriptionto be rendered.
§Returns
A string containing valid D2 source code representing the description graph.