Skip to content

Commit

Permalink
Return Vec for search
Browse files Browse the repository at this point in the history
  • Loading branch information
CathalMullan committed Aug 18, 2024
1 parent d58c525 commit c07c7b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion examples/axum-fork/src/routing/url_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ pub(super) fn insert_url_params(extensions: &mut Extensions, params: &[Parameter

let params = params
.iter()
.map(|param| (param.key.clone(), param.value.clone()))
.map(|param| {
(
String::from_utf8_lossy(&param.key),
String::from_utf8_lossy(&param.value),
)
})
.filter(|(key, _)| !key.starts_with(super::NEST_TAIL_PARAM))
.filter(|(key, _)| !key.starts_with(super::FALLBACK_PARAM))
.map(|(k, v)| {
Expand Down
2 changes: 1 addition & 1 deletion examples/hyper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn hello_route(
_: &'_ str,
parameters: &'_ [Parameter],
) -> Result<Response<BoxBody<Bytes, Infallible>>, anyhow::Error> {
let name = &parameters[0].value;
let name = String::from_utf8_lossy(&parameters[0].value);
let json = serde_json::json!({
"hello": name,
});
Expand Down
8 changes: 4 additions & 4 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct Match<'a, T> {

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

#[derive(Clone)]
Expand Down Expand Up @@ -167,8 +167,8 @@ impl<T> Router<T> {
};

Ok(Parameter {
key: std::str::from_utf8(raw.key)?.to_string(),
value: std::str::from_utf8(&value)?.to_string(),
key: raw.key.to_vec(),
value,
})
})
.collect::<Result<Vec<_>, SearchError>>()?;
Expand Down
4 changes: 2 additions & 2 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ macro_rules! assert_router_matches {
$(
$( wayfind::router::Parameter {
#[allow(clippy::string_lit_as_bytes)]
key: $param_key.to_string(),
key: $param_key.as_bytes().to_vec(),

#[allow(clippy::string_lit_as_bytes)]
value: $param_value.to_string(),
value: $param_value.as_bytes().to_vec(),
} ),+
)?
]
Expand Down

0 comments on commit c07c7b7

Please sign in to comment.