substrait_validator/output/
parse_result.rs1use crate::export;
6use crate::output::diagnostic;
7use crate::output::tree;
8
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17pub enum Validity {
18 Valid,
20
21 MaybeValid,
24
25 Invalid,
27}
28
29impl From<diagnostic::Level> for Validity {
30 fn from(level: diagnostic::Level) -> Self {
31 match level {
32 diagnostic::Level::Info => Validity::Valid,
33 diagnostic::Level::Warning => Validity::MaybeValid,
34 diagnostic::Level::Error => Validity::Invalid,
35 }
36 }
37}
38
39impl From<Validity> for diagnostic::Level {
40 fn from(validity: Validity) -> Self {
41 match validity {
42 Validity::Valid => diagnostic::Level::Info,
43 Validity::MaybeValid => diagnostic::Level::Warning,
44 Validity::Invalid => diagnostic::Level::Error,
45 }
46 }
47}
48
49pub struct ParseResult {
51 pub root: tree::Node,
53}
54
55impl ParseResult {
56 pub fn iter_diagnostics(&self) -> impl Iterator<Item = &diagnostic::Diagnostic> + '_ {
58 self.root.iter_diagnostics()
59 }
60
61 pub fn get_diagnostic(&self) -> Option<&diagnostic::Diagnostic> {
63 self.root.get_diagnostic()
64 }
65
66 pub fn check(&self) -> Validity {
68 if let Some(diag) = self.get_diagnostic() {
69 diag.adjusted_level.into()
70 } else {
71 Validity::Valid
72 }
73 }
74
75 pub fn export<T: std::io::Write>(
78 &self,
79 out: &mut T,
80 format: export::Format,
81 ) -> std::io::Result<()> {
82 export::export(out, format, "plan", self)
83 }
84}