diff --git a/examples/axum-fork/src/routing/url_params.rs b/examples/axum-fork/src/routing/url_params.rs index ae35fb82..8291f0d0 100644 --- a/examples/axum-fork/src/routing/url_params.rs +++ b/examples/axum-fork/src/routing/url_params.rs @@ -9,7 +9,7 @@ pub(crate) enum UrlParams { InvalidUtf8InPathParam { key: Arc }, } -pub(super) fn insert_url_params(extensions: &mut Extensions, params: &[Parameter]) { +pub(super) fn insert_url_params(extensions: &mut Extensions, params: &[Parameter<'_>]) { let current_params = extensions.get_mut(); if let Some(UrlParams::InvalidUtf8InPathParam { .. }) = current_params { @@ -21,7 +21,7 @@ pub(super) fn insert_url_params(extensions: &mut Extensions, params: &[Parameter .iter() .map(|param| { ( - String::from_utf8_lossy(¶m.key), + String::from_utf8_lossy(param.key), String::from_utf8_lossy(¶m.value), ) }) diff --git a/examples/hyper/src/main.rs b/examples/hyper/src/main.rs index 561c2abf..e8aff3f5 100644 --- a/examples/hyper/src/main.rs +++ b/examples/hyper/src/main.rs @@ -82,7 +82,7 @@ async fn main() -> Result<(), anyhow::Error> { async fn index_route( _: &'_ str, - _: &'_ [Parameter], + _: &'_ [Parameter<'_>], ) -> Result>, anyhow::Error> { let json = serde_json::json!({ "hello": "world" @@ -98,7 +98,7 @@ async fn index_route( async fn hello_route( _: &'_ str, - parameters: &'_ [Parameter], + parameters: &'_ [Parameter<'_>], ) -> Result>, anyhow::Error> { let name = String::from_utf8_lossy(¶meters[0].value); let json = serde_json::json!({ @@ -115,7 +115,7 @@ async fn hello_route( async fn not_found( path: &'_ str, - _: &'_ [Parameter], + _: &'_ [Parameter<'_>], ) -> Result>, anyhow::Error> { let json = serde_json::json!({ "error": "route_not_found", diff --git a/src/router.rs b/src/router.rs index 57601c66..bcb25a1d 100644 --- a/src/router.rs +++ b/src/router.rs @@ -17,12 +17,12 @@ use std::{ #[derive(Debug, Eq, PartialEq)] pub struct Match<'a, T> { pub data: &'a NodeData, - pub parameters: Vec, + pub parameters: Vec>, } #[derive(Clone, Debug, Eq, PartialEq)] -pub struct Parameter { - pub key: Vec, +pub struct Parameter<'a> { + pub key: &'a [u8], pub value: Vec, } @@ -167,7 +167,7 @@ impl Router { }; Ok(Parameter { - key: raw.key.to_vec(), + key: raw.key, value, }) }) diff --git a/tests/common.rs b/tests/common.rs index 92ba0ee3..10a5666e 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -26,7 +26,7 @@ macro_rules! assert_router_matches { $( $( wayfind::router::Parameter { #[allow(clippy::string_lit_as_bytes)] - key: $param_key.as_bytes().to_vec(), + key: $param_key.as_bytes(), #[allow(clippy::string_lit_as_bytes)] value: $param_value.as_bytes().to_vec(), @@ -41,10 +41,10 @@ macro_rules! assert_router_matches { }; } -pub struct ExpectedMatch { +pub struct ExpectedMatch<'a, T> { pub path: Arc, pub value: T, - pub params: Vec, + pub params: Vec>, } pub fn assert_router_match<'a, T: PartialEq + Debug>(