source_mesh_core/export/
exporter.rs1use std::io::Write;
2
3use anyhow::Result;
4use anyhow::ensure;
5use derive_new::new;
6use getset::CopyGetters;
7
8use crate::cycles::CycleAnalysis;
9use crate::model::FolderGraph;
10use crate::model::FolderNode;
11
12#[derive(CopyGetters, new)]
13#[getset(get_copy = "pub")]
14pub struct Options<'analysis> {
15 group_folders: bool,
16 cycles: Option<&'analysis CycleAnalysis<FolderNode>>,
17}
18
19pub trait Exporter {
20 fn write(&self, graph: &FolderGraph, output: &mut dyn Write) -> Result<()>;
21 fn write_grouped(&self, graph: &FolderGraph, output: &mut dyn Write) -> Result<()>;
22
23 fn write_with_options(&self, graph: &FolderGraph, options: &Options<'_>, output: &mut dyn Write) -> Result<()> {
24 ensure!(options.cycles().is_none(), "This exporter does not support cycle highlighting");
25 if options.group_folders() {
26 self.write_grouped(graph, output)
27 } else {
28 self.write(graph, output)
29 }
30 }
31}