substrait_validator/export/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! Module dealing with serializing a [ParseResult](parse_result::ParseResult)
4//! to a byte stream in various formats.
5
6mod diagnostics;
7mod html;
8mod proto;
9
10use crate::output::parse_result;
11
12/// Supported output formats for exporting.
13#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14pub enum Format {
15 /// Emit a newline-separated, flattened list of diagnostics.
16 Diagnostics,
17
18 /// Emit a HTML page with detailed information about the parsed plan.
19 Html,
20
21 /// Emit all parse information as a substrait.validator.Node protobuf
22 /// message, using binary serialization.
23 Proto,
24}
25
26/// Exports the given doctree with the given format to the given output.
27pub fn export<T: std::io::Write>(
28 out: &mut T,
29 format: Format,
30 root_name: &'static str,
31 result: &parse_result::ParseResult,
32) -> std::io::Result<()> {
33 match format {
34 Format::Diagnostics => diagnostics::export(out, root_name, result),
35 Format::Html => html::export(out, root_name, result),
36 Format::Proto => proto::export(out, root_name, result),
37 }
38}