substrait/parse/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Parsing of Substrait data.
4//!
5//! Some requirements of Substrait data can not be expressed via Protobuf
6//! definition or schema files. This module provides new types for the generated
7//! types, that when constructed are known to be checked. This enables producers
8//! and consumers to skip redundant checking of invariants described by the
9//! specification.
10//!
11//! This is based on the idea described in the [Parse don't
12//! validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/)
13//! blog post.
14
15use std::{error::Error, fmt::Debug};
16
17mod context;
18pub use context::Context;
19
20pub mod proto;
21pub mod text;
22
23mod typed;
24pub use typed::Anchor;
25
26/// A parse trait.
27pub trait Parse<C: Context>: Debug + Sized {
28    /// The parsed type.
29    ///
30    /// After parsing this type must be able to convert back. Note that it is
31    /// not required for the conversion to be lossless as long as the semantics
32    /// don't change.
33    ///
34    // This bound also helps with tracking breaking Protobuf definition changes
35    // via compilation errors.
36    type Parsed: Into<Self>;
37
38    /// The error type for this parser.
39    type Error: Error;
40
41    /// Parse and return a parsed type or error.
42    fn parse(self, ctx: &mut C) -> Result<Self::Parsed, Self::Error>;
43}