aboutsummaryrefslogtreecommitdiff
path: root/src/context
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-04-14 09:11:07 +0000
committerFuwn <[email protected]>2026-04-14 09:14:34 +0000
commit1b0299c102d7c9010e6684060ad3c5372d2e4c64 (patch)
tree2a3dd1f3d710f2677f94aefee3c3ae1a6062c7ee /src/context
parentperf(router)!: Pass HookContext by reference to modules and hooks (diff)
downloadarchived-windmark-1b0299c102d7c9010e6684060ad3c5372d2e4c64.tar.xz
archived-windmark-1b0299c102d7c9010e6684060ad3c5372d2e4c64.zip
perf(context)!: Replace HashMap parameters with Parameters newtype backed by Vec
Diffstat (limited to 'src/context')
-rw-r--r--src/context/hook.rs8
-rw-r--r--src/context/parameters.rs29
-rw-r--r--src/context/route.rs8
3 files changed, 37 insertions, 8 deletions
diff --git a/src/context/hook.rs b/src/context/hook.rs
index 25383f1..8ee6bac 100644
--- a/src/context/hook.rs
+++ b/src/context/hook.rs
@@ -1,15 +1,15 @@
-use std::collections::HashMap;
-
use matchit::Params;
use openssl::x509::X509;
use url::Url;
+use crate::context::Parameters;
+
#[allow(clippy::module_name_repetitions)]
#[derive(Clone)]
pub struct HookContext {
pub peer_address: Option<std::net::SocketAddr>,
pub url: Url,
- pub parameters: Option<HashMap<String, String>>,
+ pub parameters: Option<Parameters>,
pub certificate: Option<X509>,
}
@@ -24,7 +24,7 @@ impl HookContext {
Self {
peer_address: peer_address.ok(),
url,
- parameters: parameters.map(|p| crate::utilities::params_to_hashmap(&p)),
+ parameters: parameters.map(|p| Parameters::from_parameters(&p)),
certificate,
}
}
diff --git a/src/context/parameters.rs b/src/context/parameters.rs
new file mode 100644
index 0000000..413a241
--- /dev/null
+++ b/src/context/parameters.rs
@@ -0,0 +1,29 @@
+#[derive(Clone, Default)]
+pub struct Parameters(Vec<(String, String)>);
+
+impl Parameters {
+ pub(crate) fn from_parameters(parameters: &matchit::Params<'_, '_>) -> Self {
+ Self(
+ parameters
+ .iter()
+ .map(|(k, v)| (k.to_string(), v.to_string()))
+ .collect(),
+ )
+ }
+
+ #[must_use]
+ pub fn get(&self, key: &str) -> Option<&str> {
+ self
+ .0
+ .iter()
+ .find(|(k, _)| k == key)
+ .map(|(_, v)| v.as_str())
+ }
+
+ #[must_use]
+ pub const fn is_empty(&self) -> bool { self.0.is_empty() }
+
+ pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> {
+ self.0.iter().map(|(k, v)| (k.as_str(), v.as_str()))
+ }
+}
diff --git a/src/context/route.rs b/src/context/route.rs
index bcc5f2a..f175920 100644
--- a/src/context/route.rs
+++ b/src/context/route.rs
@@ -1,15 +1,15 @@
-use std::collections::HashMap;
-
use matchit::Params;
use openssl::x509::X509;
use url::Url;
+use crate::context::Parameters;
+
#[allow(clippy::module_name_repetitions)]
#[derive(Clone)]
pub struct RouteContext {
pub peer_address: Option<std::net::SocketAddr>,
pub url: Url,
- pub parameters: HashMap<String, String>,
+ pub parameters: Parameters,
pub certificate: Option<X509>,
}
@@ -24,7 +24,7 @@ impl RouteContext {
Self {
peer_address: peer_address.ok(),
url,
- parameters: crate::utilities::params_to_hashmap(parameters),
+ parameters: Parameters::from_parameters(parameters),
certificate,
}
}