Skip to content

Commit

Permalink
Post-search decode
Browse files Browse the repository at this point in the history
  • Loading branch information
CathalMullan committed Aug 18, 2024
1 parent c07c7b7 commit 60cad2e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/axum-fork/src/routing/url_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) enum UrlParams {
InvalidUtf8InPathParam { key: Arc<str> },
}

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 {
Expand All @@ -21,7 +21,7 @@ pub(super) fn insert_url_params(extensions: &mut Extensions, params: &[Parameter
.iter()
.map(|param| {
(
String::from_utf8_lossy(&param.key),
String::from_utf8_lossy(param.key),
String::from_utf8_lossy(&param.value),
)
})
Expand Down
6 changes: 3 additions & 3 deletions examples/hyper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async fn main() -> Result<(), anyhow::Error> {

async fn index_route(
_: &'_ str,
_: &'_ [Parameter],
_: &'_ [Parameter<'_>],
) -> Result<Response<BoxBody<Bytes, Infallible>>, anyhow::Error> {
let json = serde_json::json!({
"hello": "world"
Expand All @@ -98,7 +98,7 @@ async fn index_route(

async fn hello_route(
_: &'_ str,
parameters: &'_ [Parameter],
parameters: &'_ [Parameter<'_>],
) -> Result<Response<BoxBody<Bytes, Infallible>>, anyhow::Error> {
let name = String::from_utf8_lossy(&parameters[0].value);
let json = serde_json::json!({
Expand All @@ -115,7 +115,7 @@ async fn hello_route(

async fn not_found(
path: &'_ str,
_: &'_ [Parameter],
_: &'_ [Parameter<'_>],
) -> Result<Response<BoxBody<Bytes, Infallible>>, anyhow::Error> {
let json = serde_json::json!({
"error": "route_not_found",
Expand Down
8 changes: 4 additions & 4 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use std::{
#[derive(Debug, Eq, PartialEq)]
pub struct Match<'a, T> {
pub data: &'a NodeData<T>,
pub parameters: Vec<Parameter>,
pub parameters: Vec<Parameter<'a>>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Parameter {
pub key: Vec<u8>,
pub struct Parameter<'a> {
pub key: &'a [u8],
pub value: Vec<u8>,
}

Expand Down Expand Up @@ -167,7 +167,7 @@ impl<T> Router<T> {
};

Ok(Parameter {
key: raw.key.to_vec(),
key: raw.key,
value,
})
})
Expand Down
6 changes: 3 additions & 3 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -41,10 +41,10 @@ macro_rules! assert_router_matches {
};
}

pub struct ExpectedMatch<T> {
pub struct ExpectedMatch<'a, T> {
pub path: Arc<str>,
pub value: T,
pub params: Vec<Parameter>,
pub params: Vec<Parameter<'a>>,
}

pub fn assert_router_match<'a, T: PartialEq + Debug>(
Expand Down

0 comments on commit 60cad2e

Please sign in to comment.