brooks_lib/dcdn/processors/mod.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
18//! Processors for Metadata Information.
19
20use crate::{dcdn::imdi, environment::scope::Scopes, mel::interpreter::values::TypedValue, prr};
21
22pub mod cors;
23pub mod mel;
24pub mod ps;
25pub mod source;
26
27#[derive(Debug)]
28pub struct SimpleProcessorsInterpreterContext<'a> {
29 pub scopes: Scopes<TypedValue>,
30 pub mode: imdi::InterpretMode,
31 pub runtime: &'a tokio::runtime::Handle,
32 pub req: Box<dyn prr::Prr<Vec<u8>>>,
33 pub res: Option<Box<dyn prr::Prr<Vec<u8>>>>,
34}
35
36impl<'a> SimpleProcessorsInterpreterContext<'a> {
37 /// Create an interpreter context based on an existing one, but with a new RR.
38 pub fn with_res(self, res: Box<dyn prr::Prr<Vec<u8>>>) -> Self {
39 Self {
40 scopes: self.scopes,
41 mode: match res.tpe() {
42 prr::PrrType::Request => imdi::InterpretMode::Request,
43 prr::PrrType::Response => imdi::InterpretMode::Response,
44 },
45 runtime: self.runtime,
46 req: self.req,
47 res: Some(res),
48 }
49 }
50
51 pub fn with_new_value_in_scope(self, name: &str, new_value: TypedValue) -> Self {
52 Self {
53 scopes: self.scopes.insert(name, new_value),
54 mode: self.mode,
55 runtime: self.runtime,
56 req: self.req,
57 res: self.res,
58 }
59 }
60}