protovalidate-buffa 0.0.0

Runtime for protoc-gen-protovalidate-buffa — Validate trait, ValidationError types, CEL integration, rule helpers.
Documentation
//! Runtime companion for `protoc-gen-protovalidate-buffa`.

mod error;
pub mod cel;
pub mod rules;

#[cfg(feature = "connect")]
mod connect;

pub use error::{FieldPath, FieldPathElement, FieldType, Subscript, ValidationError, Violation};

// Re-export external crates referenced by plugin-generated code so that
// downstream crates only need to depend on `protovalidate-buffa` and not on
// `regex` / `cel-interpreter` directly.
pub use cel_interpreter;
pub use regex;

/// `#[auto_validate]` — attribute macro applied to a service `impl` block that
/// inserts `req.validate()?` at the top of every handler method. Guarantees
/// protovalidate runs for every RPC without relying on per-handler discipline.
pub use protovalidate_buffa_macros::auto_validate;

pub trait Validate {
    /// Runs every rule attached to this message (and any nested messages),
    /// collecting violations rather than short-circuiting on the first.
    ///
    /// # Errors
    ///
    /// Returns a [`ValidationError`] containing one or more [`Violation`]s
    /// when any rule fails. Callers typically map this to
    /// `ConnectError::invalid_argument` via
    /// [`ValidationError::into_connect_error`] (requires the `connect` feature).
    fn validate(&self) -> Result<(), ValidationError>;
}

#[macro_export]
macro_rules! field_path {
    ( $( $part:expr ),* $(,)? ) => {{
        let mut elements = ::std::vec::Vec::new();
        $(
            elements.push($crate::FieldPathElement {
                field_number: None,
                field_name: Some(::std::borrow::Cow::Borrowed($part)),
                field_type: None,
                subscript: None,
            });
        )*
        $crate::FieldPath { elements }
    }};
}