Skip to main content

brooks_lib/
visitors.rs

1// brooks, Copyright 2026, Will Hawkins
2//
3// This file is part of brooks.
4
5// This file is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18use crate::cdni::{
19    gmd::spec::TypedGenericMetadata,
20    ps::spec::{
21        TypedClientRequestStage, TypedClientResponseStage, TypedExpressionMatch, TypedHeader,
22        TypedHeaderTransform, TypedMatchGroup, TypedOriginRequestStage, TypedOriginResponseStage,
23        TypedProcessingStages, TypedRequestTransform, TypedResponseTransform, TypedStageMetadata,
24        TypedStageRules, TypedSyntheticResponse,
25    },
26};
27
28use std::fmt::Debug;
29
30/// TODO
31pub type PsVisitorResult<T, E> = Result<T, E>;
32
33/// TODO
34pub trait PsVisitor<A: Debug + Clone + Default, C, O, E> {
35    fn visit_processing_stages(
36        &mut self,
37        v: &TypedProcessingStages<A>,
38        c: C,
39    ) -> PsVisitorResult<O, E>;
40    fn visit_stage_rules(&mut self, v: &TypedStageRules<A>, c: C) -> PsVisitorResult<O, E>;
41    fn visit_expression_match(
42        &mut self,
43        v: &TypedExpressionMatch<A>,
44        c: C,
45    ) -> PsVisitorResult<O, E>;
46    fn visit_stage_metadata(&mut self, v: &TypedStageMetadata<A>, c: C) -> PsVisitorResult<O, E>;
47    fn visit_request_transform(
48        &mut self,
49        v: &TypedRequestTransform<A>,
50        c: C,
51    ) -> PsVisitorResult<O, E>;
52    fn visit_response_transform(
53        &mut self,
54        v: &TypedResponseTransform<A>,
55        c: C,
56    ) -> PsVisitorResult<O, E>;
57    fn visit_generic_metadata(
58        &mut self,
59        v: &TypedGenericMetadata<A>,
60        c: C,
61    ) -> PsVisitorResult<O, E>;
62    fn visit_header_transform(
63        &mut self,
64        v: &TypedHeaderTransform<A>,
65        c: C,
66    ) -> PsVisitorResult<O, E>;
67    fn visit_header(&mut self, v: &TypedHeader<A>, c: C) -> PsVisitorResult<O, E>;
68    fn visit_synthetic_response(
69        &mut self,
70        v: &TypedSyntheticResponse<A>,
71        c: C,
72    ) -> PsVisitorResult<O, E>;
73    fn visit_client_request_stage(
74        &mut self,
75        v: &TypedClientRequestStage<A>,
76        c: C,
77    ) -> PsVisitorResult<O, E>;
78    fn visit_client_response_stage(
79        &mut self,
80        v: &TypedClientResponseStage<A>,
81        c: C,
82    ) -> PsVisitorResult<O, E>;
83    fn visit_origin_request_stage(
84        &mut self,
85        v: &TypedOriginRequestStage<A>,
86        c: C,
87    ) -> PsVisitorResult<O, E>;
88    fn visit_origin_response_stage(
89        &mut self,
90        v: &TypedOriginResponseStage<A>,
91        c: C,
92    ) -> PsVisitorResult<O, E>;
93    fn visit_match_group(&mut self, v: &TypedMatchGroup<A>, c: C) -> PsVisitorResult<O, E>;
94}