pub struct DotWriter<'w> { /* private fields */ }
Expand description
Implementations§
Source§impl<'w> DotWriter<'w>
impl<'w> DotWriter<'w>
Sourcepub fn set_pretty_print(&mut self, pretty_print: bool)
pub fn set_pretty_print(&mut self, pretty_print: bool)
If set to true, then output will have additional whitespace including newlines and indentation to make the output more human friendly. If false then this will be left out and the output will be more compact. Defaults to true. For example disabled:
use dot_writer::DotWriter;
let mut bytes = Vec::new();
let mut writer = DotWriter::from(&mut bytes);
writer.set_pretty_print(false);
writer.graph().subgraph().cluster().subgraph();
println!("{}", std::str::from_utf8(&bytes).unwrap());
Gives you:
graph {subgraph {subgraph cluster_0 {subgraph {}}}}
While enabled:
use dot_writer::DotWriter;
let mut bytes = Vec::new();
let mut writer = DotWriter::from(&mut bytes);
// writer.set_pretty_print(false); defaults to true anyway
writer.graph().subgraph().cluster().subgraph();
println!("{}", std::str::from_utf8(&bytes).unwrap());
Gives you:
graph {
subgraph {
subgraph cluster_0 {
subgraph {}
}
}
}
Sourcepub fn graph(&mut self) -> Scope<'_, 'w>
pub fn graph(&mut self) -> Scope<'_, 'w>
Start a new undirection graph. This uses the edge operator --
automatically, which means edges should be rendered without any
arrowheads by default.
use dot_writer::DotWriter;
let mut bytes = Vec::new();
let mut writer = DotWriter::from(&mut bytes);
writer.set_pretty_print(false);
writer.graph().edge("a", "b");
assert_eq!(
std::str::from_utf8(&bytes).unwrap(),
"graph{a--b;}"
);
Sourcepub fn digraph(&mut self) -> Scope<'_, 'w>
pub fn digraph(&mut self) -> Scope<'_, 'w>
Start a new directed graph. This uses the edge operator ->
automatically, which means edges should be redered with an
arrow head pointing to the head (end) node.
use dot_writer::DotWriter;
let mut bytes = Vec::new();
let mut writer = DotWriter::from(&mut bytes);
writer.set_pretty_print(false);
writer.digraph().edge("a", "b");
assert_eq!(
std::str::from_utf8(&bytes).unwrap(),
"digraph{a->b;}"
);
Sourcepub fn write_string<F: Fn(&mut DotWriter<'_>)>(builder: F) -> String
pub fn write_string<F: Fn(&mut DotWriter<'_>)>(builder: F) -> String
Uses a callback to write DOT to a String
. This is useful
if you just want to write your dot code to a string rather than
a file or stdout, and want less boiler plate setup code.
It’s used internally for unit testing, so the output is not
pretty printed by default (but you can overwrite that by calling
DotWriter::set_pretty_print
from within the callback).
use dot_writer::DotWriter;
let output = DotWriter::write_string(|writer| {
let mut graph = writer.graph();
graph.edge("a", "b");
});
assert_eq!(output, "graph{a--b;}");