pg_parse 0.12.0

PostgreSQL parser that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree.
Documentation
use std::fmt::{Display, Formatter};

/// Error structure representing the basic error scenarios for `pg_parse`.
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Error {
    ParseError(String),
    InvalidAst(String),
    InvalidAstWithDebug(String, String),
    InvalidJson(String),
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Error::ParseError(value) => write!(f, "Parse Error: {}", value),
            Error::InvalidAst(value) => write!(f, "Invalid AST: {}", value),
            Error::InvalidAstWithDebug(value, debug) => {
                write!(f, "Invalid AST: {}. Debug: {}", value, debug)
            }
            Error::InvalidJson(value) => write!(f, "Invalid JSON: {}", value),
        }
    }
}

impl std::error::Error for Error {}

/// Convenient Result alias for returning `pg_parse::Error`.
pub type Result<T> = core::result::Result<T, Error>;