my_struct_manual/
my_struct_manual.rs1use std::error::Error;
6use std::fs::File;
7
8use vizz::DataDescription;
9use vizz::Graph;
10use vizz::Visualize;
11
12struct MyStruct<'a> {
13 my_u8: u8,
14 my_string: String,
15 my_ref: &'a String,
16}
17
18impl<'a> Visualize for MyStruct<'a> {
19 fn associated_data(&self) -> Option<Vec<DataDescription>> {
20 Some(vec![
21 DataDescription::from(&self.my_u8).with_label("my_u8"),
22 DataDescription::from(&self.my_string).with_label("my_string"),
23 DataDescription::from(&self.my_ref).with_label("my_ref"),
24 ])
25 }
26}
27
28pub fn main() -> Result<(), Box<dyn Error>> {
29 let unowned_string = String::from("yabadabadoo!");
31 let my_struct = MyStruct {
32 my_u8: 42,
33 my_string: "HELLO WORLD".into(),
34 my_ref: &unowned_string,
35 };
36
37 let mut dot_file = File::create("my_struct.dot")?;
39
40 Graph::new()
42 .add_node(&my_struct)
43 .add_node(&unowned_string)
44 .write_to(&mut dot_file)?;
45
46 Ok(())
47}