D2Describer

Struct D2Describer 

Source
pub struct D2Describer {
    pub simple_type_name: bool,
    pub show_context_in_node: bool,
    pub show_description: bool,
    pub show_externals: bool,
}
Available on crate feature 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: bool

Whether 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: bool

Whether to display the node context type inside each node.

When enabled, context will be added to node’s description.

§show_description: bool

Whether to include the node’s description.

When enabled, description will be included in the node.

§show_externals: bool

Whether to include information about external resources.

When enabled, external resources will be included in the node.

Implementations§

Source§

impl D2Describer

Source

pub fn new() -> Self

Creates a new D2Describer using default configuration.

Default settings:

  • simple_type_name: true
  • show_context_in_node: false
  • show_description: false
  • show_externals: false
Source

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;
});
Source

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
§Returns

A string containing valid D2 source code representing the description graph.

Trait Implementations§

Source§

impl Debug for D2Describer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for D2Describer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V