Skip to main content

gproxy_protocol/
lib.rs

1//! GPROXY v3 protocol model.
2//!
3//! The operation taxonomy ([`operation`]) and the OperationSpec registry
4//! ([`spec`], tables under `specs/`): every fact about an operation —
5//! ingress paths, wire kinds, settle mode, affinity — declared once and
6//! read by classification, channels, settlement, and console metadata.
7//!
8//! Public request, response, and stream-event models live under their wire
9//! family and preserve unmodeled fields through each struct's flattened rest.
10//!
11//! Enums are exhaustive under the workspace-internal `exhaustive` feature
12//! and `#[non_exhaustive]` otherwise; see Cargo.toml.
13
14pub mod aws;
15pub mod claude;
16pub mod gemini;
17pub mod openai;
18pub mod operation;
19mod path;
20pub mod spec;
21mod specs;
22
23pub use gproxy_protocol_macros::{WireBuilder, wire};
24
25#[cfg(test)]
26mod tests;
27
28pub use operation::{
29    ContentGenerationKind, Operation, OperationGroup, OperationKey, OperationKeyError,
30    OperationKind, WireFamily,
31};
32pub use path::{match_ingress, match_ingress_for, match_path, request_target};
33pub use spec::{
34    Affinity, Ingress, Matched, OperationSpec, PathPattern, Seg, SettleMode, StreamDetect,
35    StreamFraming, default_framing, streaming_sibling,
36};
37
38pub fn registered_operations() -> impl Iterator<Item = Operation> {
39    specs::REGISTRY.iter().map(|(operation, _)| *operation)
40}
41
42/// A required field was omitted while constructing an extensible wire struct.
43#[derive(Debug, Clone, PartialEq, Eq)]
44#[non_exhaustive]
45pub struct WireBuildError {
46    type_name: &'static str,
47    field: &'static str,
48}
49
50impl WireBuildError {
51    #[doc(hidden)]
52    pub const fn missing(type_name: &'static str, field: &'static str) -> Self {
53        Self { type_name, field }
54    }
55
56    pub const fn type_name(&self) -> &'static str {
57        self.type_name
58    }
59
60    pub const fn field(&self) -> &'static str {
61        self.field
62    }
63}
64
65impl std::fmt::Display for WireBuildError {
66    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67        write!(
68            formatter,
69            "missing required field `{}.{}`",
70            self.type_name, self.field
71        )
72    }
73}
74
75impl std::error::Error for WireBuildError {}