Return label from write_node_label.

Instead of appending an empty label. Because it's conceptually simpler.
This commit is contained in:
Nicholas Nethercote 2024-10-30 13:21:32 +11:00
parent a8ce44f7d9
commit d921be92a4

View File

@ -97,11 +97,10 @@ fn node_id(&self, n: &Self::Node) -> dot::Id<'_> {
}
fn node_label(&self, block: &Self::Node) -> dot::LabelText<'_> {
let mut label = Vec::new();
let mut cursor = self.cursor.borrow_mut();
let mut fmt =
BlockFormatter { cursor: &mut cursor, style: self.style, bg: Background::Light };
fmt.write_node_label(&mut label, *block).unwrap();
let label = fmt.write_node_label(*block).unwrap();
dot::LabelText::html(String::from_utf8(label).unwrap())
}
@ -172,7 +171,9 @@ fn toggle_background(&mut self) -> Background {
bg
}
fn write_node_label(&mut self, w: &mut impl io::Write, block: BasicBlock) -> io::Result<()> {
fn write_node_label(&mut self, block: BasicBlock) -> io::Result<Vec<u8>> {
use std::io::Write;
// Sample output:
// +-+-----------------------------------------------+
// A | bb4 |
@ -199,6 +200,9 @@ fn write_node_label(&mut self, w: &mut impl io::Write, block: BasicBlock) -> io:
// attributes. Make sure to test the output before trying to remove the redundancy.
// Notably, `align` was found to have no effect when applied only to <table>.
let mut v = vec![];
let w = &mut v;
let table_fmt = concat!(
" border=\"1\"",
" cellborder=\"1\"",
@ -327,7 +331,9 @@ fn write_node_label(&mut self, w: &mut impl io::Write, block: BasicBlock) -> io:
_ => {}
};
write!(w, "</table>")
write!(w, "</table>")?;
Ok(v)
}
fn write_block_header_simple(