diff --git a/doc_examples/guide/dependency_injection/cookbook/project/server_sdk/src/lib.rs b/doc_examples/guide/dependency_injection/cookbook/project/server_sdk/src/lib.rs index 001afbed5..5b691e69d 100644 --- a/doc_examples/guide/dependency_injection/cookbook/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/dependency_injection/cookbook/project/server_sdk/src/lib.rs @@ -37,31 +37,23 @@ async fn route_request( let matched_route = match server_state.router.at(&request_head.uri.path()) { Ok(m) => m, Err(_) => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( - vec![], - ) - .into(); + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter(vec![]).into(); return route_1::handler(&allowed_methods).await; } }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route - .params - .into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { - 0u32 => { - match &request_head.method { - &pavex::http::Method::GET => route_0::handler().await, - _ => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter([ - pavex::http::Method::GET, - ]) - .into(); - route_1::handler(&allowed_methods).await - } + 0u32 => match &request_head.method { + &pavex::http::Method::GET => route_0::handler().await, + _ => { + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter([pavex::http::Method::GET]).into(); + route_1::handler(&allowed_methods).await } - } + }, i => unreachable!("Unknown route id: {}", i), } } @@ -72,9 +64,7 @@ pub mod route_0 { } } pub mod route_1 { - pub async fn handler( - v0: &pavex::router::AllowedMethods, - ) -> pavex::response::Response { + pub async fn handler(v0: &pavex::router::AllowedMethods) -> pavex::response::Response { let v1 = pavex::router::default_fallback(v0).await; ::into_response(v1) } diff --git a/doc_examples/guide/dependency_injection/user_middleware/project/server_sdk/src/lib.rs b/doc_examples/guide/dependency_injection/user_middleware/project/server_sdk/src/lib.rs index 14dbe83a9..2276a7e35 100644 --- a/doc_examples/guide/dependency_injection/user_middleware/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/dependency_injection/user_middleware/project/server_sdk/src/lib.rs @@ -47,7 +47,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/doc_examples/guide/request_data/buffered_body/project/server_sdk/src/lib.rs b/doc_examples/guide/request_data/buffered_body/project/server_sdk/src/lib.rs index 001afbed5..5b691e69d 100644 --- a/doc_examples/guide/request_data/buffered_body/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/request_data/buffered_body/project/server_sdk/src/lib.rs @@ -37,31 +37,23 @@ async fn route_request( let matched_route = match server_state.router.at(&request_head.uri.path()) { Ok(m) => m, Err(_) => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( - vec![], - ) - .into(); + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter(vec![]).into(); return route_1::handler(&allowed_methods).await; } }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route - .params - .into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { - 0u32 => { - match &request_head.method { - &pavex::http::Method::GET => route_0::handler().await, - _ => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter([ - pavex::http::Method::GET, - ]) - .into(); - route_1::handler(&allowed_methods).await - } + 0u32 => match &request_head.method { + &pavex::http::Method::GET => route_0::handler().await, + _ => { + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter([pavex::http::Method::GET]).into(); + route_1::handler(&allowed_methods).await } - } + }, i => unreachable!("Unknown route id: {}", i), } } @@ -72,9 +64,7 @@ pub mod route_0 { } } pub mod route_1 { - pub async fn handler( - v0: &pavex::router::AllowedMethods, - ) -> pavex::response::Response { + pub async fn handler(v0: &pavex::router::AllowedMethods) -> pavex::response::Response { let v1 = pavex::router::default_fallback(v0).await; ::into_response(v1) } diff --git a/doc_examples/guide/request_data/json/project/server_sdk/src/lib.rs b/doc_examples/guide/request_data/json/project/server_sdk/src/lib.rs index 001afbed5..5b691e69d 100644 --- a/doc_examples/guide/request_data/json/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/request_data/json/project/server_sdk/src/lib.rs @@ -37,31 +37,23 @@ async fn route_request( let matched_route = match server_state.router.at(&request_head.uri.path()) { Ok(m) => m, Err(_) => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( - vec![], - ) - .into(); + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter(vec![]).into(); return route_1::handler(&allowed_methods).await; } }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route - .params - .into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { - 0u32 => { - match &request_head.method { - &pavex::http::Method::GET => route_0::handler().await, - _ => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter([ - pavex::http::Method::GET, - ]) - .into(); - route_1::handler(&allowed_methods).await - } + 0u32 => match &request_head.method { + &pavex::http::Method::GET => route_0::handler().await, + _ => { + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter([pavex::http::Method::GET]).into(); + route_1::handler(&allowed_methods).await } - } + }, i => unreachable!("Unknown route id: {}", i), } } @@ -72,9 +64,7 @@ pub mod route_0 { } } pub mod route_1 { - pub async fn handler( - v0: &pavex::router::AllowedMethods, - ) -> pavex::response::Response { + pub async fn handler(v0: &pavex::router::AllowedMethods) -> pavex::response::Response { let v1 = pavex::router::default_fallback(v0).await; ::into_response(v1) } diff --git a/doc_examples/guide/request_data/path/project/server_sdk/src/lib.rs b/doc_examples/guide/request_data/path/project/server_sdk/src/lib.rs index 001afbed5..5b691e69d 100644 --- a/doc_examples/guide/request_data/path/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/request_data/path/project/server_sdk/src/lib.rs @@ -37,31 +37,23 @@ async fn route_request( let matched_route = match server_state.router.at(&request_head.uri.path()) { Ok(m) => m, Err(_) => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( - vec![], - ) - .into(); + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter(vec![]).into(); return route_1::handler(&allowed_methods).await; } }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route - .params - .into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { - 0u32 => { - match &request_head.method { - &pavex::http::Method::GET => route_0::handler().await, - _ => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter([ - pavex::http::Method::GET, - ]) - .into(); - route_1::handler(&allowed_methods).await - } + 0u32 => match &request_head.method { + &pavex::http::Method::GET => route_0::handler().await, + _ => { + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter([pavex::http::Method::GET]).into(); + route_1::handler(&allowed_methods).await } - } + }, i => unreachable!("Unknown route id: {}", i), } } @@ -72,9 +64,7 @@ pub mod route_0 { } } pub mod route_1 { - pub async fn handler( - v0: &pavex::router::AllowedMethods, - ) -> pavex::response::Response { + pub async fn handler(v0: &pavex::router::AllowedMethods) -> pavex::response::Response { let v1 = pavex::router::default_fallback(v0).await; ::into_response(v1) } diff --git a/doc_examples/guide/request_data/query/project/server_sdk/src/lib.rs b/doc_examples/guide/request_data/query/project/server_sdk/src/lib.rs index 001afbed5..5b691e69d 100644 --- a/doc_examples/guide/request_data/query/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/request_data/query/project/server_sdk/src/lib.rs @@ -37,31 +37,23 @@ async fn route_request( let matched_route = match server_state.router.at(&request_head.uri.path()) { Ok(m) => m, Err(_) => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( - vec![], - ) - .into(); + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter(vec![]).into(); return route_1::handler(&allowed_methods).await; } }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route - .params - .into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { - 0u32 => { - match &request_head.method { - &pavex::http::Method::GET => route_0::handler().await, - _ => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter([ - pavex::http::Method::GET, - ]) - .into(); - route_1::handler(&allowed_methods).await - } + 0u32 => match &request_head.method { + &pavex::http::Method::GET => route_0::handler().await, + _ => { + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter([pavex::http::Method::GET]).into(); + route_1::handler(&allowed_methods).await } - } + }, i => unreachable!("Unknown route id: {}", i), } } @@ -72,9 +64,7 @@ pub mod route_0 { } } pub mod route_1 { - pub async fn handler( - v0: &pavex::router::AllowedMethods, - ) -> pavex::response::Response { + pub async fn handler(v0: &pavex::router::AllowedMethods) -> pavex::response::Response { let v1 = pavex::router::default_fallback(v0).await; ::into_response(v1) } diff --git a/doc_examples/guide/request_data/query_params/project/server_sdk/src/lib.rs b/doc_examples/guide/request_data/query_params/project/server_sdk/src/lib.rs index 001afbed5..5b691e69d 100644 --- a/doc_examples/guide/request_data/query_params/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/request_data/query_params/project/server_sdk/src/lib.rs @@ -37,31 +37,23 @@ async fn route_request( let matched_route = match server_state.router.at(&request_head.uri.path()) { Ok(m) => m, Err(_) => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( - vec![], - ) - .into(); + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter(vec![]).into(); return route_1::handler(&allowed_methods).await; } }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route - .params - .into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { - 0u32 => { - match &request_head.method { - &pavex::http::Method::GET => route_0::handler().await, - _ => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter([ - pavex::http::Method::GET, - ]) - .into(); - route_1::handler(&allowed_methods).await - } + 0u32 => match &request_head.method { + &pavex::http::Method::GET => route_0::handler().await, + _ => { + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter([pavex::http::Method::GET]).into(); + route_1::handler(&allowed_methods).await } - } + }, i => unreachable!("Unknown route id: {}", i), } } @@ -72,9 +64,7 @@ pub mod route_0 { } } pub mod route_1 { - pub async fn handler( - v0: &pavex::router::AllowedMethods, - ) -> pavex::response::Response { + pub async fn handler(v0: &pavex::router::AllowedMethods) -> pavex::response::Response { let v1 = pavex::router::default_fallback(v0).await; ::into_response(v1) } diff --git a/doc_examples/guide/request_data/request_target/project/server_sdk/src/lib.rs b/doc_examples/guide/request_data/request_target/project/server_sdk/src/lib.rs index 001afbed5..5b691e69d 100644 --- a/doc_examples/guide/request_data/request_target/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/request_data/request_target/project/server_sdk/src/lib.rs @@ -37,31 +37,23 @@ async fn route_request( let matched_route = match server_state.router.at(&request_head.uri.path()) { Ok(m) => m, Err(_) => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( - vec![], - ) - .into(); + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter(vec![]).into(); return route_1::handler(&allowed_methods).await; } }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route - .params - .into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { - 0u32 => { - match &request_head.method { - &pavex::http::Method::GET => route_0::handler().await, - _ => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter([ - pavex::http::Method::GET, - ]) - .into(); - route_1::handler(&allowed_methods).await - } + 0u32 => match &request_head.method { + &pavex::http::Method::GET => route_0::handler().await, + _ => { + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter([pavex::http::Method::GET]).into(); + route_1::handler(&allowed_methods).await } - } + }, i => unreachable!("Unknown route id: {}", i), } } @@ -72,9 +64,7 @@ pub mod route_0 { } } pub mod route_1 { - pub async fn handler( - v0: &pavex::router::AllowedMethods, - ) -> pavex::response::Response { + pub async fn handler(v0: &pavex::router::AllowedMethods) -> pavex::response::Response { let v1 = pavex::router::default_fallback(v0).await; ::into_response(v1) } diff --git a/doc_examples/guide/request_data/route_params/project-raw_route_params.snap b/doc_examples/guide/request_data/route_params/project-raw_route_params.snap index 9f7382633..7269203c6 100644 --- a/doc_examples/guide/request_data/route_params/project-raw_route_params.snap +++ b/doc_examples/guide/request_data/route_params/project-raw_route_params.snap @@ -1,8 +1,8 @@ ```rust title="src/raw_route_params/routes.rs" use pavex::http::StatusCode; -use pavex::request::route::RawRouteParams; +use pavex::request::path::RawPathParams; -pub fn handler(params: &RawRouteParams) -> StatusCode { +pub fn handler(params: &RawPathParams) -> StatusCode { for (name, value) in params.iter() { println!("`{name}` was set to `{}`", value.as_str()); } diff --git a/doc_examples/guide/request_data/route_params/project-route_params_extraction.snap b/doc_examples/guide/request_data/route_params/project-route_params_extraction.snap index 0f26cadeb..60bf077df 100644 --- a/doc_examples/guide/request_data/route_params/project-route_params_extraction.snap +++ b/doc_examples/guide/request_data/route_params/project-route_params_extraction.snap @@ -1,13 +1,13 @@ ```rust title="src/route_params/routes.rs" hl_lines="9" use pavex::http::StatusCode; -use pavex::request::route::RouteParams; +use pavex::request::path::PathParams; -#[RouteParams] +#[PathParams] pub struct GetUserParams { pub id: u64, } -pub fn handler(params: &RouteParams) -> StatusCode { +pub fn handler(params: &PathParams) -> StatusCode { println!("The user id is {}", params.0.id); StatusCode::OK } diff --git a/doc_examples/guide/request_data/route_params/project-route_params_struct_with_attr.snap b/doc_examples/guide/request_data/route_params/project-route_params_struct_with_attr.snap index 5d7f0d900..ced08da62 100644 --- a/doc_examples/guide/request_data/route_params/project-route_params_struct_with_attr.snap +++ b/doc_examples/guide/request_data/route_params/project-route_params_struct_with_attr.snap @@ -1,6 +1,6 @@ ```rust title="src/route_params/routes.rs" hl_lines="2" // [...] -#[RouteParams] +#[PathParams] pub struct GetUserParams { pub id: u64, } diff --git a/doc_examples/guide/request_data/route_params/project-route_params_typed_field.snap b/doc_examples/guide/request_data/route_params/project-route_params_typed_field.snap index 4f73622dc..3cd012e0b 100644 --- a/doc_examples/guide/request_data/route_params/project-route_params_typed_field.snap +++ b/doc_examples/guide/request_data/route_params/project-route_params_typed_field.snap @@ -1,6 +1,6 @@ ```rust title="src/route_params/routes.rs" hl_lines="4" // [...] -#[RouteParams] +#[PathParams] pub struct GetUserParams { pub id: u64, } diff --git a/doc_examples/guide/request_data/route_params/project/server_sdk/src/lib.rs b/doc_examples/guide/request_data/route_params/project/server_sdk/src/lib.rs index 001afbed5..5b691e69d 100644 --- a/doc_examples/guide/request_data/route_params/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/request_data/route_params/project/server_sdk/src/lib.rs @@ -37,31 +37,23 @@ async fn route_request( let matched_route = match server_state.router.at(&request_head.uri.path()) { Ok(m) => m, Err(_) => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( - vec![], - ) - .into(); + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter(vec![]).into(); return route_1::handler(&allowed_methods).await; } }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route - .params - .into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { - 0u32 => { - match &request_head.method { - &pavex::http::Method::GET => route_0::handler().await, - _ => { - let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter([ - pavex::http::Method::GET, - ]) - .into(); - route_1::handler(&allowed_methods).await - } + 0u32 => match &request_head.method { + &pavex::http::Method::GET => route_0::handler().await, + _ => { + let allowed_methods: pavex::router::AllowedMethods = + pavex::router::MethodAllowList::from_iter([pavex::http::Method::GET]).into(); + route_1::handler(&allowed_methods).await } - } + }, i => unreachable!("Unknown route id: {}", i), } } @@ -72,9 +64,7 @@ pub mod route_0 { } } pub mod route_1 { - pub async fn handler( - v0: &pavex::router::AllowedMethods, - ) -> pavex::response::Response { + pub async fn handler(v0: &pavex::router::AllowedMethods) -> pavex::response::Response { let v1 = pavex::router::default_fallback(v0).await; ::into_response(v1) } diff --git a/doc_examples/guide/request_data/route_params/project/src/blueprint.rs b/doc_examples/guide/request_data/route_params/project/src/blueprint.rs index e6dd927e3..255fddbd7 100644 --- a/doc_examples/guide/request_data/route_params/project/src/blueprint.rs +++ b/doc_examples/guide/request_data/route_params/project/src/blueprint.rs @@ -1,9 +1,9 @@ use pavex::blueprint::Blueprint; -use pavex::request::route::RouteParams; +use pavex::request::path::PathParams; pub fn blueprint() -> Blueprint { let mut bp = Blueprint::new(); - RouteParams::register(&mut bp); + PathParams::register(&mut bp); bp.nest(crate::route_params::blueprint()); bp } diff --git a/doc_examples/guide/request_data/route_params/project/src/raw_route_params/routes.rs b/doc_examples/guide/request_data/route_params/project/src/raw_route_params/routes.rs index 510ee0b0f..a30c7503a 100644 --- a/doc_examples/guide/request_data/route_params/project/src/raw_route_params/routes.rs +++ b/doc_examples/guide/request_data/route_params/project/src/raw_route_params/routes.rs @@ -1,7 +1,7 @@ use pavex::http::StatusCode; -use pavex::request::route::RawRouteParams; +use pavex::request::path::RawPathParams; -pub fn handler(params: &RawRouteParams) -> StatusCode { +pub fn handler(params: &RawPathParams) -> StatusCode { for (name, value) in params.iter() { println!("`{name}` was set to `{}`", value.as_str()); } diff --git a/doc_examples/guide/request_data/route_params/project/src/route_params/routes.rs b/doc_examples/guide/request_data/route_params/project/src/route_params/routes.rs index 9077fa68b..6dbac002c 100644 --- a/doc_examples/guide/request_data/route_params/project/src/route_params/routes.rs +++ b/doc_examples/guide/request_data/route_params/project/src/route_params/routes.rs @@ -1,12 +1,12 @@ use pavex::http::StatusCode; -use pavex::request::route::RouteParams; +use pavex::request::path::PathParams; -#[RouteParams] +#[PathParams] pub struct GetUserParams { pub id: u64, } -pub fn handler(params: &RouteParams) -> StatusCode { +pub fn handler(params: &PathParams) -> StatusCode { println!("The user id is {}", params.0.id); StatusCode::OK } diff --git a/doc_examples/guide/request_data/wire_data/project/server_sdk/src/lib.rs b/doc_examples/guide/request_data/wire_data/project/server_sdk/src/lib.rs index 001afbed5..60b892a63 100644 --- a/doc_examples/guide/request_data/wire_data/project/server_sdk/src/lib.rs +++ b/doc_examples/guide/request_data/wire_data/project/server_sdk/src/lib.rs @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/doc_examples/quickstart/03-route_def.snap b/doc_examples/quickstart/03-route_def.snap index 95fd7c33a..89147da36 100644 --- a/doc_examples/quickstart/03-route_def.snap +++ b/doc_examples/quickstart/03-route_def.snap @@ -1,13 +1,13 @@ ```rust title="demo/src/routes/greet.rs" -use pavex::request::route::RouteParams; +use pavex::request::path::PathParams; use pavex::response::Response; -#[RouteParams] +#[PathParams] pub struct GreetParams { pub name: String, /* (1)! */ } -pub fn greet(params: RouteParams /* (2)! */) -> Response { +pub fn greet(params: PathParams /* (2)! */) -> Response { todo!() } ``` \ No newline at end of file diff --git a/doc_examples/quickstart/03.patch b/doc_examples/quickstart/03.patch index a0e5bd82e..3fd95de0c 100644 --- a/doc_examples/quickstart/03.patch +++ b/doc_examples/quickstart/03.patch @@ -3,15 +3,15 @@ index 38ec1e3..adfbbd5 100644 --- a/demo/src/routes/greet.rs +++ b/demo/src/routes/greet.rs @@ -1,5 +1,11 @@ -+use pavex::request::route::RouteParams; ++use pavex::request::path::PathParams; use pavex::response::Response; -pub fn greet() -> Response { -+#[RouteParams] ++#[PathParams] +pub struct GreetParams { + pub name: String /* (1)! */ +} + -+pub fn greet(params: RouteParams /* (2)! */) -> Response { ++pub fn greet(params: PathParams /* (2)! */) -> Response { todo!() } diff --git a/doc_examples/quickstart/04-route_def.snap b/doc_examples/quickstart/04-route_def.snap index 4e8abe199..29d8163d2 100644 --- a/doc_examples/quickstart/04-route_def.snap +++ b/doc_examples/quickstart/04-route_def.snap @@ -1,13 +1,13 @@ ```rust title="demo/src/routes/greet.rs" -use pavex::request::route::RouteParams; +use pavex::request::path::PathParams; use pavex::response::Response; -#[RouteParams] +#[PathParams] pub struct GreetParams { pub name: String, } -pub fn greet(params: RouteParams) -> Response { +pub fn greet(params: PathParams) -> Response { let GreetParams { name }/* (1)! */ = params.0; Response::ok() // (2)! .set_typed_body(format!("Hello, {name}!")) // (3)! diff --git a/doc_examples/quickstart/04-route_params_constructor.snap b/doc_examples/quickstart/04-route_params_constructor.snap index 8ac0f2a27..748c08058 100644 --- a/doc_examples/quickstart/04-route_params_constructor.snap +++ b/doc_examples/quickstart/04-route_params_constructor.snap @@ -1,7 +1,7 @@ ```rust title="demo/src/blueprint.rs" hl_lines="3" // [...] fn register_common_constructors(bp: &mut Blueprint) { - RouteParams::register(bp); + PathParams::register(bp); // [...] } ``` \ No newline at end of file diff --git a/doc_examples/quickstart/04.patch b/doc_examples/quickstart/04.patch index 0472c280d..77c280078 100644 --- a/doc_examples/quickstart/04.patch +++ b/doc_examples/quickstart/04.patch @@ -4,15 +4,15 @@ index e0be313..5080f53 100644 +++ b/demo/src/routes/greet.rs @@ -3,9 +3,11 @@ use pavex::response::Response; - #[RouteParams] + #[PathParams] pub struct GreetParams { - pub name: String, /* (1)! */ + pub name: String, } --pub fn greet(params: RouteParams /* (2)! */) -> Response { +-pub fn greet(params: PathParams /* (2)! */) -> Response { - todo!() -+pub fn greet(params: RouteParams) -> Response { ++pub fn greet(params: PathParams) -> Response { + let GreetParams { name }/* (1)! */ = params.0; + Response::ok() // (2)! + .set_typed_body(format!("Hello, {name}!")) // (3)! diff --git a/doc_examples/quickstart/05-bis.patch b/doc_examples/quickstart/05-bis.patch index 808ba3faa..c2d3b8da2 100644 --- a/doc_examples/quickstart/05-bis.patch +++ b/doc_examples/quickstart/05-bis.patch @@ -21,8 +21,8 @@ diff --git a/demo/src/routes/greet.rs b/demo/src/routes/greet.rs pub name: String, } --pub fn greet(params: RouteParams, user_agent: UserAgent /* (1)! */) -> Response { -+pub fn greet(params: RouteParams, user_agent: UserAgent) -> Response { +-pub fn greet(params: PathParams, user_agent: UserAgent /* (1)! */) -> Response { ++pub fn greet(params: PathParams, user_agent: UserAgent) -> Response { if let UserAgent::Unknown = user_agent { return Response::unauthorized() .set_typed_body("You must provide a `User-Agent` header"); diff --git a/doc_examples/quickstart/05-error.snap b/doc_examples/quickstart/05-error.snap index 34bc0b86d..ac1b53ccd 100644 --- a/doc_examples/quickstart/05-error.snap +++ b/doc_examples/quickstart/05-error.snap @@ -12,8 +12,8 @@ β”‚ ╰──── β”‚ ╭─[demo/src/routes/greet.rs:10:1] β”‚ 10 β”‚ - β”‚ 11 β”‚ pub fn greet(params: RouteParams, user_agent: UserAgent) -> Response { - β”‚ Β·  ────┬──── + β”‚ 11 β”‚ pub fn greet(params: PathParams, user_agent: UserAgent) -> Response { + β”‚ Β·  ────┬──── β”‚ Β· I don't know how to construct an instance of this input parameter β”‚ 12 β”‚ if let UserAgent::Unknown = user_agent { β”‚ ╰──── diff --git a/doc_examples/quickstart/05-inject.snap b/doc_examples/quickstart/05-inject.snap index b3d17acea..848d65b81 100644 --- a/doc_examples/quickstart/05-inject.snap +++ b/doc_examples/quickstart/05-inject.snap @@ -2,7 +2,7 @@ // [...] use crate::user_agent::UserAgent; // [...] -pub fn greet(params: RouteParams, user_agent: UserAgent /* (1)! */) -> Response { +pub fn greet(params: PathParams, user_agent: UserAgent /* (1)! */) -> Response { if let UserAgent::Unknown = user_agent { return Response::unauthorized().set_typed_body("You must provide a `User-Agent` header"); } diff --git a/doc_examples/quickstart/05.patch b/doc_examples/quickstart/05.patch index 861051afa..9642aa4bf 100644 --- a/doc_examples/quickstart/05.patch +++ b/doc_examples/quickstart/05.patch @@ -17,21 +17,21 @@ index 5080f53..721ca61 100644 --- a/demo/src/routes/greet.rs +++ b/demo/src/routes/greet.rs @@ -1,13 +1,17 @@ - use pavex::request::route::RouteParams; + use pavex::request::path::PathParams; use pavex::response::Response; +use crate::user_agent::UserAgent; + - #[RouteParams] + #[PathParams] pub struct GreetParams { pub name: String, } --pub fn greet(params: RouteParams) -> Response { +-pub fn greet(params: PathParams) -> Response { - let GreetParams { name }/* (1)! */ = params.0; - Response::ok() // (2)! - .set_typed_body(format!("Hello, {name}!")) // (3)! -+pub fn greet(params: RouteParams, user_agent: UserAgent /* (1)! */) -> Response { ++pub fn greet(params: PathParams, user_agent: UserAgent /* (1)! */) -> Response { + if let UserAgent::Unknown = user_agent { + return Response::unauthorized().set_typed_body("You must provide a `User-Agent` header"); + } diff --git a/docs/getting_started/quickstart/dependency_injection.md b/docs/getting_started/quickstart/dependency_injection.md index cb2b4c697..648eabc97 100644 --- a/docs/getting_started/quickstart/dependency_injection.md +++ b/docs/getting_started/quickstart/dependency_injection.md @@ -10,32 +10,32 @@ it knows how to construct them. ## Constructor registration -Let's zoom in on [`RouteParams`][RouteParams]: how does the framework know how to construct it? +Let's zoom in on [`PathParams`][PathParams]: how does the framework know how to construct it? You need to go back to the [`Blueprint`][Blueprint] to find out: --8<-- "doc_examples/quickstart/04-register_common_invocation.snap" The `register_common_constructors` function takes care of registering constructors for a set of types that are defined in the `pavex` crate itself and commonly used in Pavex applications. -If you check out its definition, you'll see that it registers a constructor for [`RouteParams`][RouteParams]: +If you check out its definition, you'll see that it registers a constructor for [`PathParams`][PathParams]: --8<-- "doc_examples/quickstart/04-route_params_constructor.snap" -Inside [`RouteParams::register`][RouteParams::register] you'll find: +Inside [`PathParams::register`][PathParams::register] you'll find: ```rust use crate::blueprint::constructor::{Constructor, Lifecycle}; use crate::blueprint::Blueprint; use crate::f; -impl RouteParams<()> { +impl PathParams<()> { pub fn register(bp: &mut Blueprint) -> Constructor { bp.constructor( - f!(pavex::request::route::RouteParams::extract), + f!(pavex::request::path::PathParams::extract), Lifecycle::RequestScoped, ) .error_handler(f!( - pavex::request::route::errors::ExtractRouteParamsError::into_response + pavex::request::path::errors::ExtractPathParamsError::into_response )) } } @@ -107,8 +107,8 @@ Make sure that the project compiles successfully now. [Blueprint]: ../../api_reference/pavex/blueprint/struct.Blueprint.html -[RouteParams]: ../../api_reference/pavex/request/route/struct.RouteParams.html -[RouteParams::register]: ../../api_reference/pavex/request/route/struct.RouteParams.html#method.register +[PathParams]: ../../api_reference/pavex/request/path/struct.PathParams.html +[PathParams::register]: ../../api_reference/pavex/request/path/struct.PathParams.html#method.register [Lifecycle::Singleton]: ../../api_reference/pavex/blueprint/constructor/enum.Lifecycle.html#variant.Singleton diff --git a/docs/getting_started/quickstart/going_further.md b/docs/getting_started/quickstart/going_further.md index 0f0b17f36..1b6cff04c 100644 --- a/docs/getting_started/quickstart/going_further.md +++ b/docs/getting_started/quickstart/going_further.md @@ -14,7 +14,7 @@ need-to-know basis. [IntoResponse]: ../../api_reference/pavex/response/trait.IntoResponse.html -[RouteParams]: ../../api_reference/pavex/request/route/struct.RouteParams.html +[PathParams]: ../../api_reference/pavex/request/path/struct.PathParams.html [Response::ok]: ../../api_reference/pavex/response/struct.Response.html#method.ok diff --git a/docs/getting_started/quickstart/routing.md b/docs/getting_started/quickstart/routing.md index fe1627f03..645444f86 100644 --- a/docs/getting_started/quickstart/routing.md +++ b/docs/getting_started/quickstart/routing.md @@ -45,18 +45,18 @@ Let's register the new route with the [`Blueprint`][Blueprint] in the meantime: --8<-- "doc_examples/quickstart/02-register_new_route.snap" -1. Dynamic route parameters are prefixed with a colon (`:`). +1. Dynamic path parameters are prefixed with a colon (`:`). -## Extract route parameters +## Extract path parameters -To access the `name` route parameter from your new handler you must use the [`RouteParams`][RouteParams] extractor: +To access the `name` route parameter from your new handler you must use the [`PathParams`][PathParams] extractor: --8<-- "doc_examples/quickstart/03-route_def.snap" 1. The name of the field must match the name of the route parameter as it appears in the path we registered with the [`Blueprint`][Blueprint]. -2. The [`RouteParams`][RouteParams] extractor is generic over the type of the route parameters. +2. The [`PathParams`][PathParams] extractor is generic over the type of the path parameters. In this case, we're using the `GreetParams` type we just defined. You can now return the expected response from the `greet` handler: @@ -92,7 +92,7 @@ You should see `Hello, Ursula!` in your terminal if everything went well. [IntoResponse]: ../../api_reference/pavex/response/trait.IntoResponse.html -[RouteParams]: ../../api_reference/pavex/request/route/struct.RouteParams.html +[PathParams]: ../../api_reference/pavex/request/path/struct.PathParams.html [Response::ok]: ../../api_reference/pavex/response/struct.Response.html#method.ok diff --git a/docs/guide/dependency_injection/core_concepts/constructors.md b/docs/guide/dependency_injection/core_concepts/constructors.md index f8097b0ed..033368ad8 100644 --- a/docs/guide/dependency_injection/core_concepts/constructors.md +++ b/docs/guide/dependency_injection/core_concepts/constructors.md @@ -58,7 +58,7 @@ Let's look at a few common scenarios to build some intuition around lifecycles: |--------------------------|-------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Database connection pool | [Singleton][Lifecycle::Singleton] | The entire application should use the same pool.
Each request will fetch a connection from the pool when needed. | | HTTP client | [Singleton][Lifecycle::Singleton] | Most HTTP clients keep, under the hood, a connection pool.
You want to reuse those connections across requests to minimise latency and the number of open file descriptors. | -| Route parameters | [RequestScoped][Lifecycle::RequestScoped] | Route parameters are extracted from the incoming request.
They must not be shared across requests, therefore they can't be a [`Singleton`][Lifecycle::Singleton].
They could be [`Transient`][Lifecycle::Transient], but re-parsing the parameters before every use would be expensive.
[`RequestScoped`][Lifecycle::RequestScoped] is the optimal choice. | +| Path parameters | [RequestScoped][Lifecycle::RequestScoped] | Path parameters are extracted from the incoming request.
They must not be shared across requests, therefore they can't be a [`Singleton`][Lifecycle::Singleton].
They could be [`Transient`][Lifecycle::Transient], but re-parsing the parameters before every use would be expensive.
[`RequestScoped`][Lifecycle::RequestScoped] is the optimal choice. | | Database connection | [Transient][Lifecycle::Transient] | The connection is retrieved from a shared pool.
It could be [`RequestScoped`][Lifecycle::RequestScoped], but you might end up keeping the connection booked (i.e. outside of the pool) for longer than it's strictly necessary.
[`Transient`][Lifecycle::Transient] is the optimal choice: you only remove the connection from the pool when it's needed, put it back when idle. | | ## Recursive dependencies diff --git a/docs/guide/dependency_injection/core_concepts/framework_primitives.md b/docs/guide/dependency_injection/core_concepts/framework_primitives.md index fd5ef083b..8719f83d3 100644 --- a/docs/guide/dependency_injection/core_concepts/framework_primitives.md +++ b/docs/guide/dependency_injection/core_concepts/framework_primitives.md @@ -8,11 +8,11 @@ The framework primitives are: - [`RequestHead`][RequestHead]. The incoming request data, minus the body. - [`RawIncomingBody`][RawIncomingBody]. The raw body of the incoming request. -- [`RouteParams`][RouteParams]. The route parameters extracted from the incoming request. +- [`PathParams`][PathParams]. The path parameters extracted from the incoming request. - [`AllowedMethods`][AllowedMethods]. The HTTP methods allowed for the current request path. They represent raw data from the incoming request ([`RequestHead`][RequestHead], [`RawIncomingBody`][RawIncomingBody]) -or information coming from the routing system ([`AllowedMethods`][AllowedMethods], [`RouteParams`][RouteParams]). +or information coming from the routing system ([`AllowedMethods`][AllowedMethods], [`PathParams`][PathParams]). ## Convenient, but inflexible @@ -26,7 +26,7 @@ You lose this flexibility with framework primitives: you can't customize how the That's why we try to keep their number to a minimum. [RequestHead]: ../../../api_reference/pavex/request/struct.RequestHead.html -[RouteParams]: ../../../api_reference/pavex/request/route/struct.RouteParams.html +[PathParams]: ../../../api_reference/pavex/request/path/struct.PathParams.html [AllowedMethods]: ../../../api_reference/pavex/router/enum.AllowedMethods.html [RawIncomingBody]: ../../../api_reference/pavex/request/body/struct.RawIncomingBody.html [JsonBody]: ../../../api_reference/pavex/request/body/struct.JsonBody.html diff --git a/docs/guide/request_data/path/index.md b/docs/guide/request_data/path/index.md index e3fa53a82..995434f3a 100644 --- a/docs/guide/request_data/path/index.md +++ b/docs/guide/request_data/path/index.md @@ -4,7 +4,7 @@ The **path** is a component of the [request target](../request_target.md). E.g. `/foo/bar` is the path component in `https://example.com/foo/bar?baz=qux` or `/foo/bar?baz=qux`. The path is primarily used for [routing requests to the right handlers](../../routing/index.md). -The path can also be used to encode dynamic dataβ€”check out ["Route parameters"](route_parameters.md) for +The path can also be used to encode dynamic dataβ€”check out ["Path parameters"](path_parameters.md) for more details. ## Injection diff --git a/docs/guide/request_data/path/route_parameters.md b/docs/guide/request_data/path/path_parameters.md similarity index 68% rename from docs/guide/request_data/path/route_parameters.md rename to docs/guide/request_data/path/path_parameters.md index 4ad8b57e7..e88fef085 100644 --- a/docs/guide/request_data/path/route_parameters.md +++ b/docs/guide/request_data/path/path_parameters.md @@ -1,10 +1,10 @@ -# Route parameters +# Path parameters In REST APIs, the [path](index.md) is often used to identify a resource. For example, in `https://example.com/users/123`, the path is `/users/123` and the resource is the user with ID `123`. -Those dynamic path segments are called **route parameters**. -In Pavex, you must declare the route parameters for a given path in the route definitionβ€”see [Route parameters](../../routing/path_patterns.md#route-parameters) +Those dynamic path segments are called **path parameters**. +In Pavex, you must declare the path parameters for a given path in the route definitionβ€”see [Path parameters](../../routing/path_patterns.md#route-parameters) for more details. ## Overview @@ -16,7 +16,7 @@ To extract `123` from the path, you register `/users/:id` as the path pattern fo 1. The path pattern for the route. -You can then access the `id` value for an incoming request by injecting [`RouteParams`][RouteParams] in your handler: +You can then access the `id` value for an incoming request by injecting [`PathParams`][PathParams] in your handler: --8<-- "doc_examples/guide/request_data/route_params/project-route_params_extraction.snap" @@ -24,8 +24,8 @@ There are a few moving parts here. Let's break them down! ### Fields names -[`RouteParams`][RouteParams] is a generic wrapper around a struct[^why-struct] that models the route parameters for a given path. -All struct fields must be named after the route parameters declared in the path pattern[^wrong-name]. +[`PathParams`][PathParams] is a generic wrapper around a struct[^why-struct] that models the path parameters for a given path. +All struct fields must be named after the path parameters declared in the path pattern[^wrong-name]. In our example, the path pattern is `/users/:id`. Our extraction type, `GetUserParams`, must have a matching field named `id`. @@ -35,15 +35,15 @@ Our extraction type, `GetUserParams`, must have a matching field named `id`. ### Deserialization The newly defined struct must be **deserializable**β€”i.e. it must implement the [`serde::Deserialize`][serde::Deserialize] trait. -The [`#[RouteParams]`][RouteParamsMacro] attribute macro will automatically derive [`serde::Deserialize`][serde::Deserialize] for you. Alternatively, you can derive or implement [`serde::Deserialize`][serde::Deserialize] directly. +The [`#[PathParams]`][PathParamsMacro] attribute macro will automatically derive [`serde::Deserialize`][serde::Deserialize] for you. Alternatively, you can derive or implement [`serde::Deserialize`][serde::Deserialize] directly. --8<-- "doc_examples/guide/request_data/route_params/project-route_params_struct_with_attr.snap" -If you rely on [`#[RouteParams]`][RouteParamsMacro], Pavex can perform more advanced checks at compile time[^structural-deserialize] (e.g. detect unsupported types). +If you rely on [`#[PathParams]`][PathParamsMacro], Pavex can perform more advanced checks at compile time[^structural-deserialize] (e.g. detect unsupported types). ### Parsing -From a protocol perspective, all route parameters are strings. +From a protocol perspective, all path parameters are strings. From an application perspective, you might want to enforce stricter constraints. In our example, we expect `id` parameter to be a number. @@ -57,7 +57,7 @@ Everything works as expected because `u64` implements the [`serde::Deserialize`] ### Unsupported field types -Route parameters are best used to encode **values**, such as numbers, strings, or dates. +Path parameters are best used to encode **values**, such as numbers, strings, or dates. There is no standard way to encode more complex types such as collections (e.g. `Vec`, tuples) in a route parameter. As a result, Pavex doesn't support them. @@ -66,19 +66,19 @@ Pavex will do its best to catch unsupported types at compile time, but it's not ## Avoiding allocations If you want to squeeze out the last bit of performance from your application, -you can try to avoid heap memory allocations when extracting string-like route parameters. +you can try to avoid heap memory allocations when extracting string-like path parameters. Pavex supports this use caseβ€”**you can borrow from the request's path**. ### Percent-encoding -It is not always possible to avoid allocations when handling route parameters. -Route parameters must comply with the restriction of the URI specification: +It is not always possible to avoid allocations when handling path parameters. +Path parameters must comply with the restriction of the URI specification: you can only use [a limited set of characters](https://datatracker.ietf.org/doc/html/rfc3986#section-2). If you want to use a character not allowed in a URI, you must [percent-encode it](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). For example, if you want to use a space in a route parameter, you must encode it as `%20`. A string like `John Doe` becomes `John%20Doe` when percent-encoded. -[`RouteParams`][RouteParams] automatically decodes percent-encoded strings for you. But that comes at a cost: +[`PathParams`][PathParams] automatically decodes percent-encoded strings for you. But that comes at a cost: Pavex _must_ allocate a new `String` if the route parameter is percent-encoded. ### Cow @@ -89,32 +89,32 @@ It borrows from the request's path if possible, it allocates a new `String` if i [`Cow<'_, str>`][Cow] strikes a balance between performance and robustness: you don't have to worry about a runtime error if the route parameter is percent-encoded, but you tried to use `&str` as its field type. -## `RawRouteParams` +## `RawPathParams` -[`RouteParams`][RouteParams] is a high-level interface: it bundles together compile-time checks, +[`PathParams`][PathParams] is a high-level interface: it bundles together compile-time checks, extraction and parsing. -If you want to opt out of all those utilities, reach for [`RawRouteParams`][RawRouteParams]. +If you want to opt out of all those utilities, reach for [`RawPathParams`][RawPathParams]. It is a lower-level interface[^relationship]: it gives you access to the dynamic path segments as they appear right after extraction. It doesn't perform percent-decoding not deserialization. ### Injection -[`RawRouteParams`][RawRouteParams] is a [framework primitive](../../dependency_injection/core_concepts/framework_primitives.md), +[`RawPathParams`][RawPathParams] is a [framework primitive](../../dependency_injection/core_concepts/framework_primitives.md), you don't have to register a constructor to inject it. --8<-- "doc_examples/guide/request_data/route_params/project-raw_route_params.snap" ### Allocations -[`RawRouteParams`][RawRouteParams] tries to avoid heap memory allocations. +[`RawPathParams`][RawPathParams] tries to avoid heap memory allocations. Parameter names are borrowed from the server routing machinery. Parameter values are borrowed from the [raw path](index.md) of the incoming request. You might have to allocate when you decode [percent-encoded parameters](#percent-encoding). -[^why-struct]: Pavex made a deliberate choice of _not_ supporting tuples or other sequence-like types for extracting route parameters. -Check out [the API reference](../../../api_reference/pavex/request/route/struct.RouteParams.html#unsupported-types) +[^why-struct]: Pavex made a deliberate choice of _not_ supporting tuples or other sequence-like types for extracting path parameters. +Check out [the API reference](../../../api_reference/pavex/request/path/struct.PathParams.html#unsupported-types) to learn more about the rationale behind this decision. [^wrong-name]: If a field name doesn't match a route parameter name, Pavex will detect it at compile time and return @@ -124,13 +124,13 @@ No more runtime errors because you misspelled a field name! [^structural-deserialize]: Check the documentation for [`StructuralDeserialize`][StructuralDeserialize] if you want to know more about the underlying mechanism. -[^relationship]: [`RouteParams`][RouteParams] is built on top of [`RawRouteParams`][RawRouteParams]. +[^relationship]: [`PathParams`][PathParams] is built on top of [`RawPathParams`][RawPathParams]. [RequestHead]: ../../../api_reference/pavex/request/struct.RequestHead.html [RequestHead::target]: ../../../api_reference/pavex/request/struct.RequestHead.html#structfield.target -[RouteParams]: ../../../api_reference/pavex/request/route/struct.RouteParams.html -[RouteParamsMacro]: ../../../api_reference/pavex/request/route/attr.RouteParams.html +[PathParams]: ../../../api_reference/pavex/request/path/struct.PathParams.html +[PathParamsMacro]: ../../../api_reference/pavex/request/path/attr.PathParams.html [serde::Deserialize]: https://docs.rs/serde/latest/serde/trait.Deserialize.html [StructuralDeserialize]: ../../../api_reference/pavex/serialization/trait.StructuralDeserialize.html [Cow]: https://doc.rust-lang.org/std/borrow/enum.Cow.html -[RawRouteParams]: ../../../api_reference/pavex/request/route/struct.RawRouteParams.html +[RawPathParams]: ../../../api_reference/pavex/request/path/struct.RawPathParams.html diff --git a/docs/guide/request_data/request_target.md b/docs/guide/request_data/request_target.md index 638ae1aff..446024fbe 100644 --- a/docs/guide/request_data/request_target.md +++ b/docs/guide/request_data/request_target.md @@ -28,7 +28,7 @@ Inject [`RequestHead`][RequestHead] to access the request target via its [`targe The raw target and its components are primarily useful for logging purposes. Rely on higher-level abstractions -to perform more advanced processingβ€”e.g. parsing query parameters or [route parameters](path/route_parameters.md). +to perform more advanced processingβ€”e.g. parsing query parameters or [path parameters](path/path_parameters.md). [^rfc]: [RFC 7230](https://datatracker.ietf.org/doc/html/rfc7230#section-5.3) allows two other formats of request target, authority form (e.g. `example.com:443`) and asterisk form (e.g. `*`). diff --git a/docs/guide/routing/path_patterns.md b/docs/guide/routing/path_patterns.md index dd34305f4..7e1dcc99b 100644 --- a/docs/guide/routing/path_patterns.md +++ b/docs/guide/routing/path_patterns.md @@ -12,7 +12,7 @@ The simplest case is a static path, a path pattern that matches a single, fixed It will only match requests with a path that is **exactly equal** to `/greet`. -## Route parameters +## Path parameters Static paths are fairly limited. The real power of path patterns comes from their ability to match **dynamic paths**: @@ -24,7 +24,7 @@ The `:name` segment is a **route parameter**. It matches everything after `/greet/`, up to the next `/` or the end of the path. It matches, for example, `/greet/Ursula` and `/greet/John`. It won't match `/greet/` though! -You can have multiple route parameters in a single path pattern, as long as they are separated by a static segment: +You can have multiple path parameters in a single path pattern, as long as they are separated by a static segment: ```rust hl_lines="8" --8<-- "doc_examples/guide/routing/path_patterns/multi_named_parameter/src/blueprint.rs" @@ -32,7 +32,7 @@ You can have multiple route parameters in a single path pattern, as long as they ## Catch-all parameters -Route parameters prefixed with a `:` only match a single path segmentβ€”they stop at the next `/` or at the end of the path. +Path parameters prefixed with a `:` only match a single path segmentβ€”they stop at the next `/` or at the end of the path. You can use the `*` character to craft a **catch-all** route parameter. It matches the rest of the path, regardless of its contents: ```rust hl_lines="6" @@ -45,12 +45,12 @@ You can use the `*` character to craft a **catch-all** route parameter. It match To avoid ambiguity, you can have **at most one catch-all parameter per path pattern** and it must be **at the end of the path pattern**. -## Accessing route parameters +## Accessing path parameters -Route parameters are not discarded after a request has been routed. +Path parameters are not discarded after a request has been routed. You can access their values from your request handler or from middlewares. -Check out the ["Route parameters"](../request_data/path/route_parameters.md) guide for more details. +Check out the ["Path parameters"](../request_data/path/path_parameters.md) guide for more details. -[RouteParams]: ../../api_reference/pavex/request/route/struct.RouteParams.html +[PathParams]: ../../api_reference/pavex/request/path/struct.PathParams.html diff --git a/examples/realworld/api_server_sdk/blueprint.ron b/examples/realworld/api_server_sdk/blueprint.ron index 0e51d7ddd..c8bb67c44 100644 --- a/examples/realworld/api_server_sdk/blueprint.ron +++ b/examples/realworld/api_server_sdk/blueprint.ron @@ -35,7 +35,7 @@ constructor: ( callable: ( registered_at: "conduit_core", - import_path: "pavex::request::route::RouteParams::extract", + import_path: "pavex::request::path::PathParams::extract", ), location: ( line: 42, @@ -48,7 +48,7 @@ error_handler: Some(( callable: ( registered_at: "conduit_core", - import_path: "pavex::request::route::errors::ExtractRouteParamsError::into_response", + import_path: "pavex::request::path::errors::ExtractPathParamsError::into_response", ), location: ( line: 46, diff --git a/examples/realworld/api_server_sdk/src/lib.rs b/examples/realworld/api_server_sdk/src/lib.rs index a1efd5568..7d17c9dc0 100644 --- a/examples/realworld/api_server_sdk/src/lib.rs +++ b/examples/realworld/api_server_sdk/src/lib.rs @@ -89,7 +89,7 @@ async fn route_request( vec![], ) .into(); - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "*", ); return route_2::middleware_0( @@ -102,12 +102,12 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { 0u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/api/ping", ); match &request_head.method { @@ -129,7 +129,7 @@ async fn route_request( } } 1u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/articles", ); match &request_head.method { @@ -160,7 +160,7 @@ async fn route_request( } } 2u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/articles/:slug", ); match &request_head.method { @@ -206,7 +206,7 @@ async fn route_request( } } 3u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/articles/:slug/comments", ); match &request_head.method { @@ -243,7 +243,7 @@ async fn route_request( } } 4u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/articles/:slug/comments/:comment_id", ); match &request_head.method { @@ -270,7 +270,7 @@ async fn route_request( } } 5u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/articles/:slug/favorite", ); match &request_head.method { @@ -306,7 +306,7 @@ async fn route_request( } } 6u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/articles/feed", ); match &request_head.method { @@ -328,7 +328,7 @@ async fn route_request( } } 7u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/profiles/:username", ); match &request_head.method { @@ -355,7 +355,7 @@ async fn route_request( } } 8u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/profiles/:username/follow", ); match &request_head.method { @@ -391,7 +391,7 @@ async fn route_request( } } 9u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/tags", ); match &request_head.method { @@ -413,7 +413,7 @@ async fn route_request( } } 10u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/user", ); match &request_head.method { @@ -444,7 +444,7 @@ async fn route_request( } } 11u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/users", ); match &request_head.method { @@ -473,7 +473,7 @@ async fn route_request( } } 12u32 => { - let matched_route_template = pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = pavex::request::path::MatchedPathPattern::new( "/users/login", ); match &request_head.method { @@ -506,7 +506,7 @@ async fn route_request( } pub mod route_0 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: &pavex::request::RequestHead, ) -> pavex::response::Response { let v2 = conduit_core::telemetry::RootSpan::new(v1, v0); @@ -539,7 +539,7 @@ pub mod route_0 { } pub mod route_1 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: &pavex::request::RequestHead, ) -> pavex::response::Response { let v2 = conduit_core::telemetry::RootSpan::new(v1, v0); @@ -572,7 +572,7 @@ pub mod route_1 { } pub mod route_2 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: &pavex::router::AllowedMethods, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { @@ -610,7 +610,7 @@ pub mod route_2 { } pub mod route_3 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: &sqlx_core::driver_prelude::pool::Pool, v2: &jsonwebtoken::EncodingKey, v3: pavex::request::body::RawIncomingBody, @@ -706,7 +706,7 @@ pub mod route_3 { } pub mod route_4 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: &sqlx_core::driver_prelude::pool::Pool, v2: &jsonwebtoken::EncodingKey, v3: pavex::request::body::RawIncomingBody, @@ -802,7 +802,7 @@ pub mod route_4 { } pub mod route_5 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: &pavex::request::RequestHead, ) -> pavex::response::Response { let v2 = conduit_core::telemetry::RootSpan::new(v1, v0); @@ -835,7 +835,7 @@ pub mod route_5 { } pub mod route_6 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: pavex::request::body::RawIncomingBody, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { @@ -908,8 +908,8 @@ pub mod route_6 { } pub mod route_7 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -921,14 +921,14 @@ pub mod route_7 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -944,8 +944,8 @@ pub mod route_7 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where @@ -960,8 +960,8 @@ pub mod route_7 { } pub mod route_8 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -973,14 +973,14 @@ pub mod route_8 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -996,8 +996,8 @@ pub mod route_8 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where @@ -1012,8 +1012,8 @@ pub mod route_8 { } pub mod route_9 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -1025,14 +1025,14 @@ pub mod route_9 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -1048,8 +1048,8 @@ pub mod route_9 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where @@ -1064,7 +1064,7 @@ pub mod route_9 { } pub mod route_10 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: &pavex::request::RequestHead, ) -> pavex::response::Response { let v2 = conduit_core::telemetry::RootSpan::new(v1, v0); @@ -1113,7 +1113,7 @@ pub mod route_10 { } pub mod route_11 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: pavex::request::body::RawIncomingBody, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { @@ -1186,7 +1186,7 @@ pub mod route_11 { } pub mod route_12 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, + v0: pavex::request::path::MatchedPathPattern, v1: &pavex::request::RequestHead, ) -> pavex::response::Response { let v2 = conduit_core::telemetry::RootSpan::new(v1, v0); @@ -1235,8 +1235,8 @@ pub mod route_12 { } pub mod route_13 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -1248,14 +1248,14 @@ pub mod route_13 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -1271,8 +1271,8 @@ pub mod route_13 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where @@ -1287,8 +1287,8 @@ pub mod route_13 { } pub mod route_14 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -1300,14 +1300,14 @@ pub mod route_14 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -1323,8 +1323,8 @@ pub mod route_14 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where @@ -1339,8 +1339,8 @@ pub mod route_14 { } pub mod route_15 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: pavex::request::body::RawIncomingBody, v3: &pavex::request::RequestHead, ) -> pavex::response::Response { @@ -1356,7 +1356,7 @@ pub mod route_15 { } pub async fn handler( v0: pavex::request::body::RawIncomingBody, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = ::default(); @@ -1388,12 +1388,12 @@ pub mod route_15 { }; } }; - let v8 = pavex::request::route::RouteParams::extract(v1); + let v8 = pavex::request::path::PathParams::extract(v1); let v9 = match v8 { Ok(ok) => ok, Err(v9) => { return { - let v10 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v10 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v9, ); ::into_response( @@ -1410,11 +1410,11 @@ pub mod route_15 { T: std::future::Future, { s_0: pavex::request::body::RawIncomingBody, - s_1: pavex::request::route::RawRouteParams<'a, 'b>, + s_1: pavex::request::path::RawPathParams<'a, 'b>, s_2: &'c pavex::request::RequestHead, next: fn( pavex::request::body::RawIncomingBody, - pavex::request::route::RawRouteParams<'a, 'b>, + pavex::request::path::RawPathParams<'a, 'b>, &'c pavex::request::RequestHead, ) -> T, } @@ -1431,8 +1431,8 @@ pub mod route_15 { } pub mod route_16 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -1444,14 +1444,14 @@ pub mod route_16 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -1467,8 +1467,8 @@ pub mod route_16 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where @@ -1483,8 +1483,8 @@ pub mod route_16 { } pub mod route_17 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -1496,14 +1496,14 @@ pub mod route_17 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -1519,8 +1519,8 @@ pub mod route_17 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where @@ -1535,8 +1535,8 @@ pub mod route_17 { } pub mod route_18 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -1548,14 +1548,14 @@ pub mod route_18 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -1571,8 +1571,8 @@ pub mod route_18 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where @@ -1587,8 +1587,8 @@ pub mod route_18 { } pub mod route_19 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: pavex::request::body::RawIncomingBody, v3: &pavex::request::RequestHead, ) -> pavex::response::Response { @@ -1604,7 +1604,7 @@ pub mod route_19 { } pub async fn handler( v0: pavex::request::body::RawIncomingBody, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = ::default(); @@ -1636,12 +1636,12 @@ pub mod route_19 { }; } }; - let v8 = pavex::request::route::RouteParams::extract(v1); + let v8 = pavex::request::path::PathParams::extract(v1); let v9 = match v8 { Ok(ok) => ok, Err(v9) => { return { - let v10 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v10 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v9, ); ::into_response( @@ -1658,11 +1658,11 @@ pub mod route_19 { T: std::future::Future, { s_0: pavex::request::body::RawIncomingBody, - s_1: pavex::request::route::RawRouteParams<'a, 'b>, + s_1: pavex::request::path::RawPathParams<'a, 'b>, s_2: &'c pavex::request::RequestHead, next: fn( pavex::request::body::RawIncomingBody, - pavex::request::route::RawRouteParams<'a, 'b>, + pavex::request::path::RawPathParams<'a, 'b>, &'c pavex::request::RequestHead, ) -> T, } @@ -1679,8 +1679,8 @@ pub mod route_19 { } pub mod route_20 { pub async fn middleware_0( - v0: pavex::request::route::MatchedRouteTemplate, - v1: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::MatchedPathPattern, + v1: pavex::request::path::RawPathParams<'_, '_>, v2: &pavex::request::RequestHead, ) -> pavex::response::Response { let v3 = conduit_core::telemetry::RootSpan::new(v2, v0); @@ -1692,14 +1692,14 @@ pub mod route_20 { conduit_core::telemetry::logger(v5, v3).await } pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -1715,8 +1715,8 @@ pub mod route_20 { where T: std::future::Future, { - s_0: pavex::request::route::RawRouteParams<'a, 'b>, - next: fn(pavex::request::route::RawRouteParams<'a, 'b>) -> T, + s_0: pavex::request::path::RawPathParams<'a, 'b>, + next: fn(pavex::request::path::RawPathParams<'a, 'b>) -> T, } impl<'a, 'b, T> std::future::IntoFuture for Next0<'a, 'b, T> where diff --git a/examples/realworld/conduit_core/src/blueprint.rs b/examples/realworld/conduit_core/src/blueprint.rs index 116ba2333..84b6a2735 100644 --- a/examples/realworld/conduit_core/src/blueprint.rs +++ b/examples/realworld/conduit_core/src/blueprint.rs @@ -40,11 +40,11 @@ fn register_common_constructors(bp: &mut Blueprint) { // Route parameters bp.constructor( - f!(pavex::request::route::RouteParams::extract), + f!(pavex::request::path::PathParams::extract), Lifecycle::RequestScoped, ) .error_handler(f!( - pavex::request::route::errors::ExtractRouteParamsError::into_response + pavex::request::path::errors::ExtractPathParamsError::into_response )); // Json body diff --git a/examples/realworld/conduit_core/src/routes/articles/delete_article.rs b/examples/realworld/conduit_core/src/routes/articles/delete_article.rs index f284291aa..1fd28c607 100644 --- a/examples/realworld/conduit_core/src/routes/articles/delete_article.rs +++ b/examples/realworld/conduit_core/src/routes/articles/delete_article.rs @@ -1,11 +1,11 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct DeleteArticle { pub slug: String, } -pub fn delete_article(_params: RouteParams) -> StatusCode { +pub fn delete_article(_params: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/routes/articles/delete_comment.rs b/examples/realworld/conduit_core/src/routes/articles/delete_comment.rs index 5876b31c6..94e2be653 100644 --- a/examples/realworld/conduit_core/src/routes/articles/delete_comment.rs +++ b/examples/realworld/conduit_core/src/routes/articles/delete_comment.rs @@ -1,12 +1,12 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct DeleteComment { pub slug: String, pub comment_id: u64, } -pub fn delete_comment(_route: RouteParams) -> StatusCode { +pub fn delete_comment(_route: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/routes/articles/favorite_article.rs b/examples/realworld/conduit_core/src/routes/articles/favorite_article.rs index 5895fd34c..1a1b23558 100644 --- a/examples/realworld/conduit_core/src/routes/articles/favorite_article.rs +++ b/examples/realworld/conduit_core/src/routes/articles/favorite_article.rs @@ -1,9 +1,9 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; use crate::schemas::Article; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct FavoriteArticle { pub slug: String, } @@ -14,6 +14,6 @@ pub struct FavoriteArticleResponse { pub article: Article, } -pub fn favorite_article(_params: RouteParams) -> StatusCode { +pub fn favorite_article(_params: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/routes/articles/get_article.rs b/examples/realworld/conduit_core/src/routes/articles/get_article.rs index a34971f24..4b6fb4ab4 100644 --- a/examples/realworld/conduit_core/src/routes/articles/get_article.rs +++ b/examples/realworld/conduit_core/src/routes/articles/get_article.rs @@ -1,9 +1,9 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; use crate::schemas::Article; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct GetArticle { pub slug: String, } @@ -14,6 +14,6 @@ pub struct GetArticleResponse { pub article: Article, } -pub fn get_article(_params: RouteParams) -> StatusCode { +pub fn get_article(_params: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/routes/articles/list_comments.rs b/examples/realworld/conduit_core/src/routes/articles/list_comments.rs index a1d018f6f..2ef7c9bf3 100644 --- a/examples/realworld/conduit_core/src/routes/articles/list_comments.rs +++ b/examples/realworld/conduit_core/src/routes/articles/list_comments.rs @@ -1,9 +1,9 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; use crate::schemas::Comment; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct ListComments { pub slug: String, } @@ -14,6 +14,6 @@ pub struct ListCommentsResponse { pub comments: Vec, } -pub fn list_comments(_route: RouteParams) -> StatusCode { +pub fn list_comments(_route: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/routes/articles/publish_comment.rs b/examples/realworld/conduit_core/src/routes/articles/publish_comment.rs index e959e9224..5036fbe09 100644 --- a/examples/realworld/conduit_core/src/routes/articles/publish_comment.rs +++ b/examples/realworld/conduit_core/src/routes/articles/publish_comment.rs @@ -1,12 +1,12 @@ use pavex::{ http::StatusCode, - request::{body::JsonBody, route::RouteParams}, + request::{body::JsonBody, path::PathParams}, }; use crate::schemas::Comment; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct PublishCommentRoute { pub slug: String, } @@ -30,7 +30,7 @@ pub struct PublishCommentResponse { } pub fn publish_comment( - _route: RouteParams, + _route: PathParams, _body: JsonBody, ) -> StatusCode { StatusCode::OK diff --git a/examples/realworld/conduit_core/src/routes/articles/unfavorite_article.rs b/examples/realworld/conduit_core/src/routes/articles/unfavorite_article.rs index 5fd95b271..74d8c7dba 100644 --- a/examples/realworld/conduit_core/src/routes/articles/unfavorite_article.rs +++ b/examples/realworld/conduit_core/src/routes/articles/unfavorite_article.rs @@ -1,9 +1,9 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; use crate::schemas::Article; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct UnfavoriteArticle { pub slug: String, } @@ -14,6 +14,6 @@ pub struct UnfavoriteArticleResponse { pub article: Article, } -pub fn unfavorite_article(_params: RouteParams) -> StatusCode { +pub fn unfavorite_article(_params: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/routes/articles/update_article.rs b/examples/realworld/conduit_core/src/routes/articles/update_article.rs index 0626996a3..0bcf7bf03 100644 --- a/examples/realworld/conduit_core/src/routes/articles/update_article.rs +++ b/examples/realworld/conduit_core/src/routes/articles/update_article.rs @@ -1,6 +1,6 @@ use pavex::{ http::StatusCode, - request::{body::JsonBody, route::RouteParams}, + request::{body::JsonBody, path::PathParams}, }; use crate::schemas::Article; @@ -14,7 +14,7 @@ pub struct UpdateArticleBody { } #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct UpdateArticleRoute { pub slug: String, } @@ -26,7 +26,7 @@ pub struct UpdateArticleResponse { } pub fn update_article( - _params: RouteParams, + _params: PathParams, _body: JsonBody, ) -> StatusCode { StatusCode::OK diff --git a/examples/realworld/conduit_core/src/routes/profiles/follow_profile.rs b/examples/realworld/conduit_core/src/routes/profiles/follow_profile.rs index d6a1ebb53..162ca5ba6 100644 --- a/examples/realworld/conduit_core/src/routes/profiles/follow_profile.rs +++ b/examples/realworld/conduit_core/src/routes/profiles/follow_profile.rs @@ -1,9 +1,9 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; use crate::schemas::Profile; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct FollowProfile { pub username: String, } @@ -14,6 +14,6 @@ pub struct FollowProfileResponse { pub profile: Profile, } -pub fn follow_profile(_params: RouteParams) -> StatusCode { +pub fn follow_profile(_params: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/routes/profiles/get_profile.rs b/examples/realworld/conduit_core/src/routes/profiles/get_profile.rs index a42e3a8cd..f973a8200 100644 --- a/examples/realworld/conduit_core/src/routes/profiles/get_profile.rs +++ b/examples/realworld/conduit_core/src/routes/profiles/get_profile.rs @@ -1,9 +1,9 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; use crate::schemas::Profile; #[derive(Debug)] -#[RouteParams] +#[PathParams] pub struct GetProfile { pub username: String, } @@ -14,6 +14,6 @@ pub struct GetProfileResponse { pub profile: Profile, } -pub fn get_profile(_params: RouteParams) -> StatusCode { +pub fn get_profile(_params: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/routes/profiles/unfollow_profile.rs b/examples/realworld/conduit_core/src/routes/profiles/unfollow_profile.rs index 0b2377322..89adf3aaf 100644 --- a/examples/realworld/conduit_core/src/routes/profiles/unfollow_profile.rs +++ b/examples/realworld/conduit_core/src/routes/profiles/unfollow_profile.rs @@ -1,8 +1,8 @@ -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; use crate::schemas::Profile; -#[RouteParams] +#[PathParams] #[derive(Debug)] pub struct UnfollowProfile { pub username: String, @@ -14,6 +14,6 @@ pub struct UnfollowProfileResponse { pub profile: Profile, } -pub fn unfollow_profile(_params: RouteParams) -> StatusCode { +pub fn unfollow_profile(_params: PathParams) -> StatusCode { StatusCode::OK } diff --git a/examples/realworld/conduit_core/src/telemetry.rs b/examples/realworld/conduit_core/src/telemetry.rs index ff4536953..22fedc7be 100644 --- a/examples/realworld/conduit_core/src/telemetry.rs +++ b/examples/realworld/conduit_core/src/telemetry.rs @@ -1,6 +1,6 @@ use pavex::http::Version; use pavex::middleware::Next; -use pavex::request::route::MatchedRouteTemplate; +use pavex::request::path::MatchedPathPattern; use pavex::request::RequestHead; use pavex::response::Response; use std::borrow::Cow; @@ -24,7 +24,7 @@ impl RootSpan { /// /// We follow OpenTelemetry's HTTP semantic conventions as closely as /// possible for field naming. - pub fn new(request_head: &RequestHead, matched_route: MatchedRouteTemplate) -> Self { + pub fn new(request_head: &RequestHead, matched_route: MatchedPathPattern) -> Self { let user_agent = request_head .headers .get("User-Agent") diff --git a/examples/skeleton/app_server_sdk/src/lib.rs b/examples/skeleton/app_server_sdk/src/lib.rs index 6469c5d83..c0aa764dd 100644 --- a/examples/skeleton/app_server_sdk/src/lib.rs +++ b/examples/skeleton/app_server_sdk/src/lib.rs @@ -50,7 +50,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex/src/blueprint/blueprint.rs b/libs/pavex/src/blueprint/blueprint.rs index 7cbdf1447..6fae212a5 100644 --- a/libs/pavex/src/blueprint/blueprint.rs +++ b/libs/pavex/src/blueprint/blueprint.rs @@ -97,7 +97,7 @@ impl Blueprint { /// ``` /// /// [`router`]: crate::blueprint::router - /// [`RouteParams`]: struct@crate::request::route::RouteParams + /// [`PathParams`]: struct@crate::request::path::PathParams pub fn route(&mut self, method_guard: MethodGuard, path: &str, callable: RawCallable) -> Route { let registered_route = RegisteredRoute { path: path.to_owned(), diff --git a/libs/pavex/src/request/mod.rs b/libs/pavex/src/request/mod.rs index 1553d6986..84293a175 100644 --- a/libs/pavex/src/request/mod.rs +++ b/libs/pavex/src/request/mod.rs @@ -2,6 +2,6 @@ pub use request_head::RequestHead; pub mod body; +pub mod path; pub mod query; mod request_head; -pub mod route; diff --git a/libs/pavex/src/request/route/deserializer.rs b/libs/pavex/src/request/path/deserializer.rs similarity index 98% rename from libs/pavex/src/request/route/deserializer.rs rename to libs/pavex/src/request/path/deserializer.rs index 8fa187de7..7842dbc94 100644 --- a/libs/pavex/src/request/route/deserializer.rs +++ b/libs/pavex/src/request/path/deserializer.rs @@ -36,7 +36,7 @@ use serde::{ forward_to_deserialize_any, Deserializer, }; -use crate::request::route::errors::{ErrorKind, PathDeserializationError}; +use crate::request::path::errors::{ErrorKind, PathDeserializationError}; macro_rules! unsupported_type { ($trait_fn:ident) => { @@ -734,7 +734,7 @@ mod tests { vec![("a", "c"), ("a", "B")], Vec, ErrorKind::UnsupportedType { - name: "alloc::vec::Vec" + name: "alloc::vec::Vec" } ); @@ -745,7 +745,7 @@ mod tests { TupleStruct, ErrorKind::UnsupportedType { name: - "pavex::request::route::deserializer::tests::test_unsupported_seq::TupleStruct" + "pavex::request::path::deserializer::tests::test_unsupported_seq::TupleStruct" } ); diff --git a/libs/pavex/src/request/route/errors.rs b/libs/pavex/src/request/path/errors.rs similarity index 86% rename from libs/pavex/src/request/route/errors.rs rename to libs/pavex/src/request/path/errors.rs index d3f745783..c0d2bf4e9 100644 --- a/libs/pavex/src/request/route/errors.rs +++ b/libs/pavex/src/request/path/errors.rs @@ -3,17 +3,17 @@ use std::str::Utf8Error; use crate::response::Response; -/// The error returned by [`RouteParams::extract`] when the extraction fails. +/// The error returned by [`PathParams::extract`] when the extraction fails. /// -/// See [`RouteParams::extract`] and the documentation of each error variant for more details. +/// See [`PathParams::extract`] and the documentation of each error variant for more details. /// -/// Pavex provides [`ExtractRouteParamsError::into_response`] as the default error handler for +/// Pavex provides [`ExtractPathParamsError::into_response`] as the default error handler for /// this failure. /// -/// [`RouteParams::extract`]: crate::request::route::RouteParams::extract +/// [`PathParams::extract`]: crate::request::path::PathParams::extract #[derive(Debug, thiserror::Error)] #[non_exhaustive] -pub enum ExtractRouteParamsError { +pub enum ExtractPathParamsError { #[error(transparent)] /// See [`InvalidUtf8InPathParam`] for details. InvalidUtf8InPathParameter(InvalidUtf8InPathParam), @@ -30,7 +30,7 @@ pub enum ExtractRouteParamsError { /// URL safeβ€”e.g. whitespaces. /// /// Pavex automatically percent-decodes URL parameters before trying to deserialize them -/// in [`RouteParams`]. +/// in [`PathParams`]. /// This error is returned whenever the percent-decoding step failsβ€”i.e. the decoded data is not a /// valid UTF8 string. /// @@ -44,7 +44,7 @@ pub enum ExtractRouteParamsError { /// decoded, is a sequence of bytes that cannot be interpreted as a well-formed UTF8 string. /// This error is then returned. /// -/// [`RouteParams`]: struct@crate::request::route::RouteParams +/// [`PathParams`]: struct@crate::request::path::PathParams #[error( "`{invalid_raw_segment}` cannot be used as `{invalid_key}` \ since it is not a well-formed UTF8 string when percent-decoded" @@ -79,20 +79,20 @@ pub struct DecodeError { pub(super) source: Utf8Error, } -impl ExtractRouteParamsError { - /// Convert an [`ExtractRouteParamsError`] into an HTTP response. +impl ExtractPathParamsError { + /// Convert an [`ExtractPathParamsError`] into an HTTP response. /// /// It returns a `500 Internal Server Error` to the caller if the failure was caused by a - /// programmer error (e.g. `T` in [`RouteParams`] is an unsupported type). + /// programmer error (e.g. `T` in [`PathParams`] is an unsupported type). /// It returns a `400 Bad Request` for all other cases. /// - /// [`RouteParams`]: struct@crate::request::route::RouteParams + /// [`PathParams`]: struct@crate::request::path::PathParams pub fn into_response(&self) -> Response { match self { - ExtractRouteParamsError::InvalidUtf8InPathParameter(e) => { + ExtractPathParamsError::InvalidUtf8InPathParameter(e) => { Response::bad_request().set_typed_body(format!("Invalid URL.\n{}", e)) } - ExtractRouteParamsError::PathDeserializationError(e) => match e.kind { + ExtractPathParamsError::PathDeserializationError(e) => match e.kind { ErrorKind::ParseErrorAtKey { .. } | ErrorKind::ParseError { .. } => { Response::bad_request().set_typed_body(format!("Invalid URL.\n{}", e.kind)) } @@ -110,11 +110,11 @@ impl ExtractRouteParamsError { #[derive(Debug)] /// Something went wrong when trying to deserialize the percent-decoded URL parameters into -/// the target type you specifiedβ€”`T` in [`RouteParams`]. +/// the target type you specifiedβ€”`T` in [`PathParams`]. /// /// You can use [`PathDeserializationError::kind`] to get more details about the error. /// -/// [`RouteParams`]: struct@crate::request::route::RouteParams +/// [`PathParams`]: struct@crate::request::path::PathParams pub struct PathDeserializationError { pub(super) kind: ErrorKind, } @@ -156,13 +156,13 @@ impl std::fmt::Display for PathDeserializationError { impl std::error::Error for PathDeserializationError {} -/// The kinds of errors that can happen when deserializing into a [`RouteParams`]. +/// The kinds of errors that can happen when deserializing into a [`PathParams`]. /// /// This type is obtained through [`PathDeserializationError::kind`] and is useful for building /// more precise error messages (e.g. implementing your own custom conversion from /// [`PathDeserializationError`] into an HTTP response). /// -/// [`RouteParams`]: struct@crate::request::route::RouteParams +/// [`PathParams`]: struct@crate::request::path::PathParams #[derive(Debug, PartialEq, Eq)] #[non_exhaustive] pub enum ErrorKind { @@ -208,7 +208,7 @@ impl std::fmt::Display for ErrorKind { ErrorKind::UnsupportedType { name } => { write!( f, - "`{name}` is not a supported type for the `RouteParams` extractor. \ + "`{name}` is not a supported type for the `PathParams` extractor. \ The type `T` in `Path` must be a struct (with one public field for each \ templated path segment) or a map (e.g. `HashMap<&'a str, Cow<'a, str>>`)." ) diff --git a/libs/pavex/src/request/route/matched_route.rs b/libs/pavex/src/request/path/matched_path.rs similarity index 65% rename from libs/pavex/src/request/route/matched_route.rs rename to libs/pavex/src/request/path/matched_path.rs index 0fdef7881..1014f3088 100644 --- a/libs/pavex/src/request/route/matched_route.rs +++ b/libs/pavex/src/request/path/matched_path.rs @@ -18,32 +18,37 @@ use std::fmt::Formatter; /// # } /// ``` /// -/// Then [`MatchedRouteTemplate`] will be set to `/home/:home_id` for a `GET /home/123` request. +/// Then [`MatchedPathPattern`] will be set to `/home/:home_id` for a `GET /home/123` request. /// /// # Framework primitive /// -/// `MatchedRouteTemplate` is a framework primitiveβ€”you don't need to register any constructor +/// `MatchedPathPattern` is a framework primitiveβ€”you don't need to register any constructor /// with [`Blueprint`] to use it in your application. /// /// # Use cases /// -/// The primary use case for [`MatchedRouteTemplate`] is telemetryβ€”logging, metrics, etc. +/// The primary use case for [`MatchedPathPattern`] is telemetryβ€”logging, metrics, etc. /// It lets you strip away the dynamic parts of the request path, thus reducing the cardinality of /// your metrics and making it easier to aggregate them. /// /// [`Blueprint`]: crate::blueprint::Blueprint #[doc(alias("MatchedPath"))] -pub struct MatchedRouteTemplate(&'static str); +#[doc(alias("MatchedPathTemplate"))] +#[doc(alias("PathPattern"))] +#[doc(alias("PathTemplate"))] +#[doc(alias("MatchedRoute"))] +#[doc(alias("MatchedRouteTemplate"))] +pub struct MatchedPathPattern(&'static str); -impl MatchedRouteTemplate { +impl MatchedPathPattern { /// Create a new matched route from a route template. /// /// # Example /// /// ```rust - /// use pavex::request::route::MatchedRouteTemplate; + /// use pavex::request::path::MatchedPathPattern; /// - /// let matched_route = MatchedRouteTemplate::new("/home/:home_id"); + /// let matched_route = MatchedPathPattern::new("/home/:home_id"); /// ``` pub fn new(route: &'static str) -> Self { Self(route) @@ -55,7 +60,7 @@ impl MatchedRouteTemplate { } } -impl std::fmt::Display for MatchedRouteTemplate { +impl std::fmt::Display for MatchedPathPattern { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } diff --git a/libs/pavex/src/request/route/mod.rs b/libs/pavex/src/request/path/mod.rs similarity index 65% rename from libs/pavex/src/request/route/mod.rs rename to libs/pavex/src/request/path/mod.rs index 4c152766d..7609f5b2e 100644 --- a/libs/pavex/src/request/route/mod.rs +++ b/libs/pavex/src/request/path/mod.rs @@ -4,8 +4,8 @@ //! //! When it comes to route information, there are two important extractors to be aware of: //! -//! - [`RouteParams`]: extract route parameters from the URL of incoming requests -//! - [`MatchedRouteTemplate`]: extract the route template that matched for the incoming request +//! - [`PathParams`]: extract route parameters from the URL of incoming requests +//! - [`MatchedPathPattern`]: extract the route template that matched for the incoming request //! //! Check out their documentation for more details. //! @@ -14,7 +14,7 @@ //! ```rust //! use pavex::f; //! use pavex::blueprint::{router::GET, Blueprint, constructor::Lifecycle}; -//! use pavex::request::route::RouteParams; +//! use pavex::request::path::PathParams; //! //! fn blueprint() -> Blueprint{ //! let mut bp = Blueprint::new(); @@ -24,32 +24,33 @@ //! bp //! } //! -//! // The RouteParams attribute macro derives the necessary (de)serialization traits. -//! #[RouteParams] +//! // The PathParams attribute macro derives the necessary (de)serialization traits. +//! #[PathParams] //! struct Home { //! // The name of the field must match the name of the route parameter //! // used in `bp.route`. //! home_id: u32 //! } //! -//! // The `RouteParams` extractor deserializes the extracted route parameters into +//! // The `PathParams` extractor deserializes the extracted route parameters into //! // the type you specifiedβ€”`Home` in this case. -//! fn get_home(params: &RouteParams) -> String { +//! fn get_home(params: &PathParams) -> String { //! format!("The identifier for this home is: {}", params.0.home_id) //! } //! ``` //! -//! Check out [`RouteParams`]' documentation for more details. +//! Check out [`PathParams`]' documentation for more details. //! -//! [`RouteParams`]: struct@RouteParams +//! [`PathParams`]: struct@PathParams -pub use matched_route::MatchedRouteTemplate; +pub use matched_path::MatchedPathPattern; +pub use path_params::PathParams; /// Derive (de)serialization logic for a type that is going to be used to extract route parameters. /// /// This macro derives [`StructuralDeserialize`], [`serde::Serialize`] and [`serde::Deserialize`] /// for the type that it is applied to. /// -/// Check out [`RouteParams`](struct@RouteParams) for more details on how to work with +/// Check out [`PathParams`](struct@PathParams) for more details on how to work with /// route parameters in Pavex. /// Check out [`StructuralDeserialize`] if you are curious about the rationale behind this /// macro. @@ -59,7 +60,7 @@ pub use matched_route::MatchedRouteTemplate; /// ```rust /// use pavex::f; /// use pavex::blueprint::{router::GET, Blueprint, constructor::Lifecycle}; -/// use pavex::request::route::RouteParams; +/// use pavex::request::path::PathParams; /// /// fn blueprint() -> Blueprint { /// /// let mut bp = Blueprint::new(); @@ -69,24 +70,23 @@ pub use matched_route::MatchedRouteTemplate; /// # bp /// } /// -/// #[RouteParams] +/// #[PathParams] /// struct Home { /// home_id: u32 /// } /// -/// fn get_home(params: &RouteParams) -> String { +/// fn get_home(params: &PathParams) -> String { /// format!("The identifier for this home is: {}", params.0.home_id) /// } /// ``` /// /// [`StructuralDeserialize`]: crate::serialization::StructuralDeserialize -pub use pavex_macros::RouteParams; -pub use raw_route_params::{EncodedParamValue, RawRouteParams, RawRouteParamsIter}; -pub use route_params::RouteParams; +pub use pavex_macros::PathParams; +pub use raw_path_params::{EncodedParamValue, RawPathParams, RawPathParamsIter}; mod deserializer; pub mod errors; -mod matched_route; -mod raw_route_params; -mod route_params; +mod matched_path; +mod path_params; +mod raw_path_params; diff --git a/libs/pavex/src/request/route/route_params.rs b/libs/pavex/src/request/path/path_params.rs similarity index 74% rename from libs/pavex/src/request/route/route_params.rs rename to libs/pavex/src/request/path/path_params.rs index bf7449795..a8075f973 100644 --- a/libs/pavex/src/request/route/route_params.rs +++ b/libs/pavex/src/request/path/path_params.rs @@ -3,10 +3,10 @@ use serde::Deserialize; use crate::blueprint::constructor::{Constructor, Lifecycle}; use crate::blueprint::Blueprint; use crate::f; -use crate::request::route::deserializer::PathDeserializer; -use crate::request::route::errors::{DecodeError, ExtractRouteParamsError, InvalidUtf8InPathParam}; +use crate::request::path::deserializer::PathDeserializer; +use crate::request::path::errors::{DecodeError, ExtractPathParamsError, InvalidUtf8InPathParam}; -use super::RawRouteParams; +use super::RawPathParams; /// Extract (typed) route parameters from the URL of an incoming request. /// @@ -24,28 +24,28 @@ use super::RawRouteParams; /// ```rust /// use pavex::f; /// use pavex::blueprint::{router::GET, Blueprint, constructor::Lifecycle}; -/// use pavex::request::route::RouteParams; +/// use pavex::request::path::PathParams; /// /// fn blueprint() -> Blueprint { /// let mut bp = Blueprint::new(); -/// // Register the default constructor and error handler for `RouteParams`. -/// RouteParams::register(&mut bp); +/// // Register the default constructor and error handler for `PathParams`. +/// PathParams::register(&mut bp); /// // Register a route with a route parameter, `:home_id`. /// bp.route(GET, "/home/:home_id", f!(crate::get_home)); /// bp /// } /// -/// // The RouteParams attribute macro derives the necessary (de)serialization traits. -/// #[RouteParams] +/// // The PathParams attribute macro derives the necessary (de)serialization traits. +/// #[PathParams] /// pub struct Home { /// // The name of the field must match the name of the route parameter /// // used in `bp.route`. /// home_id: u32 /// } /// -/// // The `RouteParams` extractor deserializes the extracted route parameters into -/// // the type you specifiedβ€”`HomeRouteParams` in this case. -/// pub fn get_home(params: &RouteParams) -> String { +/// // The `PathParams` extractor deserializes the extracted route parameters into +/// // the type you specifiedβ€”`HomePathParams` in this case. +/// pub fn get_home(params: &PathParams) -> String { /// format!("The identifier for this home is: {}", params.0.home_id) /// } /// ``` @@ -55,8 +55,8 @@ use super::RawRouteParams; /// /// # Supported types /// -/// `T` in `RouteParams` must implement [`serde::Deserialize`]β€”it is automatically derived if -/// you use the [`RouteParams`](macro@crate::request::route::RouteParams) attribute macro, the +/// `T` in `PathParams` must implement [`serde::Deserialize`]β€”it is automatically derived if +/// you use the [`PathParams`](macro@crate::request::path::PathParams) attribute macro, the /// approach we recommend. /// `T` must be a struct with named fields, where each field name matches one of the route parameter /// names used in the route's path template. @@ -64,7 +64,7 @@ use super::RawRouteParams; /// ```rust /// use pavex::f; /// use pavex::blueprint::{router::GET, Blueprint}; -/// use pavex::request::route::RouteParams; +/// use pavex::request::path::PathParams; /// /// fn blueprint() -> Blueprint{ /// let mut bp = Blueprint::new(); @@ -74,7 +74,7 @@ use super::RawRouteParams; /// bp /// } /// -/// #[RouteParams] +/// #[PathParams] /// pub struct Room { /// // The name of the extracted fields must match the names of the route parameters /// // used in the template we passed to `bp.route`. @@ -84,9 +84,9 @@ use super::RawRouteParams; /// // extracting the `room_id` here. /// } /// -/// // The `RouteParams` extractor will deserialize the route parameters into the +/// // The `PathParams` extractor will deserialize the route parameters into the /// // type you specifiedβ€”`Room` in this case. -/// pub fn get_room(params: &RouteParams) -> String { +/// pub fn get_room(params: &PathParams) -> String { /// let params = ¶ms.0; /// format!("The home with id {} is in street {}", params.home_id, params.street_id) /// } @@ -102,18 +102,18 @@ use super::RawRouteParams; /// check the route's path template to understand what each entry represents. /// ///```rust -/// use pavex::request::route::RouteParams; +/// use pavex::request::path::PathParams; /// /// // This is self-documenting βœ… /// // No need to check the route's path template to understand what each field represents. -/// #[RouteParams] +/// #[PathParams] /// pub struct Room { /// home_id: u32, /// room_id: u32, /// street_id: u32, /// } /// -/// pub fn get_room(params: &RouteParams) -> String { +/// pub fn get_room(params: &PathParams) -> String { /// // [...] /// # unimplemented!() /// } @@ -121,13 +121,13 @@ use super::RawRouteParams; /// // This isn't self-documenting ❌ /// // What does the second u32 represent? The room id? The street id? /// // Impossible to tell without checking the route's path template. -/// pub fn get_room_tuple(params: &RouteParams<(u32, u32, u32)>) -> String { +/// pub fn get_room_tuple(params: &PathParams<(u32, u32, u32)>) -> String { /// // [...] /// # unimplemented!() /// } /// ``` /// -/// For this reason, Pavex does not support the following types as `T` in `RouteParams`: +/// For this reason, Pavex does not support the following types as `T` in `PathParams`: /// /// - tuples, e.g. `(u32, String)`; /// - tuple structs, e.g. `struct HomeId(u32, String)`; @@ -139,15 +139,15 @@ use super::RawRouteParams; /// # Additional compile-time checks /// /// Pavex is able to perform additional checks at compile-time if you use the -/// [`RouteParams`](macro@crate::request::route::RouteParams) macro instead +/// [`PathParams`](macro@crate::request::path::PathParams) macro instead /// of deriving [`serde::Deserialize`] on your own. /// /// ```rust /// # mod home { -/// use pavex::request::route::RouteParams; +/// use pavex::request::path::PathParams; /// /// // Do this πŸ‘‡ -/// #[RouteParams] +/// #[PathParams] /// pub struct Home { /// home_id: u32 /// } @@ -171,7 +171,7 @@ use super::RawRouteParams; /// instead of `Cow<'_, str>` (see [`Avoiding allocations`](#avoiding-allocations)). /// /// Check out [`StructuralDeserialize`](crate::serialization::StructuralDeserialize) if you are curious -/// to know more about the role played by the [`RouteParams`](macro@crate::request::route::RouteParams) +/// to know more about the role played by the [`PathParams`](macro@crate::request::path::PathParams) /// macro in enabling these additional compile-time checks. /// /// # Avoiding allocations @@ -188,15 +188,15 @@ use super::RawRouteParams; /// URL if possible, and allocates a new `String` only if strictly necessary. /// /// ```rust -/// use pavex::request::route::RouteParams; +/// use pavex::request::path::PathParams; /// use std::borrow::Cow; /// -/// #[RouteParams] +/// #[PathParams] /// pub struct Payee<'a> { /// name: Cow<'a, str>, /// } /// -/// pub fn get_payee(params: &RouteParams>) -> String { +/// pub fn get_payee(params: &PathParams>) -> String { /// format!("The payee's name is {}", params.0.name) /// } /// ``` @@ -211,23 +211,23 @@ use super::RawRouteParams; /// are extracted from the URL, before any kind of percent-decoding or deserialization has taken /// place. /// -/// You can do so by using the [`RawRouteParams`] extractor instead of [`RouteParams`]. Check out -/// [`RawRouteParams`]' documentation for more information. +/// You can do so by using the [`RawPathParams`] extractor instead of [`PathParams`]. Check out +/// [`RawPathParams`]' documentation for more information. #[doc(alias = "Path")] -#[doc(alias = "PathParams")] +#[doc(alias = "RouteParams")] #[doc(alias = "UrlParams")] -pub struct RouteParams( +pub struct PathParams( /// The extracted route parameters, deserialized into `T`, the type you specified. pub T, ); -impl RouteParams { - /// The default constructor for [`RouteParams`]. +impl PathParams { + /// The default constructor for [`PathParams`]. /// - /// If the extraction fails, an [`ExtractRouteParamsError`] is returned. + /// If the extraction fails, an [`ExtractPathParamsError`] is returned. pub fn extract<'server, 'request>( - params: RawRouteParams<'server, 'request>, - ) -> Result + params: RawPathParams<'server, 'request>, + ) -> Result where T: Deserialize<'request>, // The parameter ids live as long as the server, while the values are tied to the lifecycle @@ -241,7 +241,7 @@ impl RouteParams { invalid_raw_segment, source, } = e; - ExtractRouteParamsError::InvalidUtf8InPathParameter(InvalidUtf8InPathParam { + ExtractPathParamsError::InvalidUtf8InPathParameter(InvalidUtf8InPathParam { invalid_key: id.into(), invalid_raw_segment, source, @@ -251,22 +251,22 @@ impl RouteParams { } let deserializer = PathDeserializer::new(&decoded_params); T::deserialize(deserializer) - .map_err(ExtractRouteParamsError::PathDeserializationError) - .map(RouteParams) + .map_err(ExtractPathParamsError::PathDeserializationError) + .map(PathParams) } } -impl RouteParams<()> { - /// Register the [default constructor](RouteParams::extract) - /// and [error handler](ExtractRouteParamsError::into_response) - /// for [`RouteParams`] with a [`Blueprint`]. +impl PathParams<()> { + /// Register the [default constructor](PathParams::extract) + /// and [error handler](ExtractPathParamsError::into_response) + /// for [`PathParams`] with a [`Blueprint`]. pub fn register(bp: &mut Blueprint) -> Constructor { bp.constructor( - f!(pavex::request::route::RouteParams::extract), + f!(pavex::request::path::PathParams::extract), Lifecycle::RequestScoped, ) .error_handler(f!( - pavex::request::route::errors::ExtractRouteParamsError::into_response + pavex::request::path::errors::ExtractPathParamsError::into_response )) } } diff --git a/libs/pavex/src/request/route/raw_route_params.rs b/libs/pavex/src/request/path/raw_path_params.rs similarity index 74% rename from libs/pavex/src/request/route/raw_route_params.rs rename to libs/pavex/src/request/path/raw_path_params.rs index 6333e31d6..7fbe76811 100644 --- a/libs/pavex/src/request/route/raw_route_params.rs +++ b/libs/pavex/src/request/path/raw_path_params.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use matchit::{Params, ParamsIter}; use percent_encoding::percent_decode_str; -use crate::request::route::errors::DecodeError; +use crate::request::path::errors::DecodeError; /// Extract (raw) route parameters from the URL of an incoming request. /// @@ -12,7 +12,7 @@ use crate::request::route::errors::DecodeError; /// ```rust /// use pavex::f; /// use pavex::blueprint::{router::GET, Blueprint}; -/// use pavex::request::route::RawRouteParams; +/// use pavex::request::path::RawPathParams; /// /// fn blueprint() -> Blueprint { /// let mut bp = Blueprint::new(); @@ -22,7 +22,7 @@ use crate::request::route::errors::DecodeError; /// bp /// } /// -/// pub fn get_home(params: &RawRouteParams) -> String { +/// pub fn get_home(params: &RawPathParams) -> String { /// let home_id = ¶ms.get("home_id").unwrap(); /// let street_id = ¶ms.get("street_id").unwrap(); /// format!("The home with id {} is in street {}", home_id, street_id) @@ -31,7 +31,7 @@ use crate::request::route::errors::DecodeError; /// /// # Framework primitive /// -/// `RawRouteParams` is a framework primitiveβ€”you don't need to register any constructor +/// `RawPathParams` is a framework primitiveβ€”you don't need to register any constructor /// with `Blueprint` to use it in your application. /// /// # What does "raw" mean? @@ -43,29 +43,29 @@ use crate::request::route::errors::DecodeError; /// If you want to send "123 456" as a route parameter, you have to percent-encode it: it becomes /// "123%20456" since "%20" is the percent-encoding for a space character. /// -/// `RawRouteParams` gives you access to the **raw** route parameters, i.e. the route parameters +/// `RawPathParams` gives you access to the **raw** route parameters, i.e. the route parameters /// as they are extracted from the URL, before any kind of processing has taken /// place. /// -/// In particular, `RawRouteParams` does **not** perform any percent-decoding. -/// If you send a request to `/address/123%20456/home/789`, the `RawRouteParams` for +/// In particular, `RawPathParams` does **not** perform any percent-decoding. +/// If you send a request to `/address/123%20456/home/789`, the `RawPathParams` for /// `/address/:address_id/home/:home_id` will contain the following key-value pairs: /// /// - `address_id`: `123%20456` /// - `home_id`: `789` /// -/// `address_id` is not `123 456` because `RawRouteParams` does not perform percent-decoding! +/// `address_id` is not `123 456` because `RawPathParams` does not perform percent-decoding! /// Therefore `%20` is not interpreted as a space character. /// /// There are situations where you might want to work with the raw route parameters, but -/// most of the time you'll want to use [`RouteParams`] insteadβ€”it performs percent-decoding +/// most of the time you'll want to use [`PathParams`] insteadβ€”it performs percent-decoding /// and deserialization for you. /// -/// [`RouteParams`]: struct@crate::request::route::RouteParams +/// [`PathParams`]: struct@crate::request::path::PathParams #[derive(Debug, PartialEq, Eq, Clone)] -pub struct RawRouteParams<'server, 'request>(Params<'server, 'request>); +pub struct RawPathParams<'server, 'request>(Params<'server, 'request>); -impl<'server, 'request> RawRouteParams<'server, 'request> { +impl<'server, 'request> RawPathParams<'server, 'request> { /// Returns the number of extracted route parameters. pub fn len(&self) -> usize { self.0.len() @@ -77,8 +77,8 @@ impl<'server, 'request> RawRouteParams<'server, 'request> { } /// Returns an iterator over the parameters in the list. - pub fn iter(&self) -> RawRouteParamsIter<'_, 'server, 'request> { - RawRouteParamsIter(self.0.iter()) + pub fn iter(&self) -> RawPathParamsIter<'_, 'server, 'request> { + RawPathParamsIter(self.0.iter()) } /// Returns `true` if no route parameters have been extracted from the request URL. @@ -87,18 +87,18 @@ impl<'server, 'request> RawRouteParams<'server, 'request> { } } -impl<'k, 'v> From> for RawRouteParams<'k, 'v> { +impl<'k, 'v> From> for RawPathParams<'k, 'v> { fn from(value: Params<'k, 'v>) -> Self { Self(value) } } -/// An iterator over the route parameters extracted via [`RawRouteParams`]. -pub struct RawRouteParamsIter<'extractor, 'server, 'request>( +/// An iterator over the route parameters extracted via [`RawPathParams`]. +pub struct RawPathParamsIter<'extractor, 'server, 'request>( ParamsIter<'extractor, 'server, 'request>, ); -impl<'extractor, 'server, 'request> Iterator for RawRouteParamsIter<'extractor, 'server, 'request> { +impl<'extractor, 'server, 'request> Iterator for RawPathParamsIter<'extractor, 'server, 'request> { type Item = (&'server str, EncodedParamValue<'request>); fn next(&mut self) -> Option { @@ -108,7 +108,7 @@ impl<'extractor, 'server, 'request> Iterator for RawRouteParamsIter<'extractor, } } -/// A wrapper around a percent-encoded route parameter, obtained via [`RawRouteParams`]. +/// A wrapper around a percent-encoded route parameter, obtained via [`RawPathParams`]. /// /// Use [`decode`](Self::decode) to extract the percent-encoded value. #[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] diff --git a/libs/pavex/src/request/query/query_params.rs b/libs/pavex/src/request/query/query_params.rs index 84c8b6ccd..3329411e5 100644 --- a/libs/pavex/src/request/query/query_params.rs +++ b/libs/pavex/src/request/query/query_params.rs @@ -27,8 +27,8 @@ use super::errors::{ExtractQueryParamsError, QueryDeserializationError}; /// home_id: u32 /// } /// -/// // The `RouteParams` extractor deserializes the extracted route parameters into -/// // the type you specifiedβ€”`HomeRouteParams` in this case. +/// // The `PathParams` extractor deserializes the extracted route parameters into +/// // the type you specifiedβ€”`HomePathParams` in this case. /// pub fn get_home(params: &QueryParams) -> String { /// format!("The identifier for this home is: {}", params.0.home_id) /// } @@ -103,7 +103,7 @@ use super::errors::{ExtractQueryParamsError, QueryDeserializationError}; /// /// # Unsupported types /// -/// Pavex does not support the following types as `T` in `RouteParams`: +/// Pavex does not support the following types as `T` in `PathParams`: /// /// - tuples, e.g. `(u32, String)`; /// - tuple structs, e.g. `struct HomeId(u32, String)`; diff --git a/libs/pavex/src/serialization.rs b/libs/pavex/src/serialization.rs index 73a32bd28..1dfe19d53 100644 --- a/libs/pavex/src/serialization.rs +++ b/libs/pavex/src/serialization.rs @@ -2,7 +2,7 @@ /// A marker trait for types that perform deserialization using the strategy provided "out-of-the-box" by `serde`. /// -/// All types that derive `RouteParams` automatically implement this trait. +/// All types that derive `PathParams` automatically implement this trait. /// It is **discouraged** to manually implement this trait for one of your typesβ€”and you should /// have no need to do so. /// diff --git a/libs/pavex_cli/tests/ui_tests/app_builder/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/app_builder/expectations/app.rs index 3f9e2ff0e..c1f1e13e1 100644 --- a/libs/pavex_cli/tests/ui_tests/app_builder/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/app_builder/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/common/async_callable_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/common/async_callable_are_supported/expectations/app.rs index 76bd31054..084666c32 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/common/async_callable_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/common/async_callable_are_supported/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/common/components_can_fail/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/common/components_can_fail/expectations/app.rs index 192cf2331..80dd7c914 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/common/components_can_fail/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/common/components_can_fail/expectations/app.rs @@ -53,7 +53,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -65,7 +65,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/constructors/output_type_of_constructors_can_contain_generic_parameters/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/constructors/output_type_of_constructors_can_contain_generic_parameters/expectations/app.rs index 713d743ff..a438d2a8c 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/constructors/output_type_of_constructors_can_contain_generic_parameters/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/constructors/output_type_of_constructors_can_contain_generic_parameters/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/constructors/static_references_are_valid_singletons/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/constructors/static_references_are_valid_singletons/expectations/app.rs index 56e16fddd..f56d17639 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/constructors/static_references_are_valid_singletons/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/constructors/static_references_are_valid_singletons/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/constructors/the_latest_registered_constructor_takes_precedence/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/constructors/the_latest_registered_constructor_takes_precedence/expectations/app.rs index 8ab50aed1..bf72a29bd 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/constructors/the_latest_registered_constructor_takes_precedence/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/constructors/the_latest_registered_constructor_takes_precedence/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/constructors/the_same_constructor_can_be_registered_multiple_times_using_the_same_lifecycle/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/constructors/the_same_constructor_can_be_registered_multiple_times_using_the_same_lifecycle/expectations/app.rs index 53f439d58..8f93e84d8 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/constructors/the_same_constructor_can_be_registered_multiple_times_using_the_same_lifecycle/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/constructors/the_same_constructor_can_be_registered_multiple_times_using_the_same_lifecycle/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/nesting/application_state_should_include_runtime_singletons_from_all_scopes/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/nesting/application_state_should_include_runtime_singletons_from_all_scopes/expectations/app.rs index 77137d7e9..cce3e5eee 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/nesting/application_state_should_include_runtime_singletons_from_all_scopes/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/nesting/application_state_should_include_runtime_singletons_from_all_scopes/expectations/app.rs @@ -43,7 +43,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -55,7 +55,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/nesting/multiple_levels_of_nesting_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/nesting/multiple_levels_of_nesting_are_supported/expectations/app.rs index 080096987..56c93f3bf 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/nesting/multiple_levels_of_nesting_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/nesting/multiple_levels_of_nesting_are_supported/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/router/fallback_priority/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/router/fallback_priority/expectations/app.rs index 87c96e9c1..7b0d4716e 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/router/fallback_priority/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/router/fallback_priority/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/router/http_method_routing_variants/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/blueprint/router/http_method_routing_variants/expectations/app.rs index 123f1975f..dd1035da1 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/router/http_method_routing_variants/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/blueprint/router/http_method_routing_variants/expectations/app.rs @@ -47,7 +47,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -59,7 +59,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/blueprint/router/invalid_paths/expectations/stderr.txt b/libs/pavex_cli/tests/ui_tests/blueprint/router/invalid_paths/expectations/stderr.txt index 4904dcf45..31c44e893 100644 --- a/libs/pavex_cli/tests/ui_tests/blueprint/router/invalid_paths/expectations/stderr.txt +++ b/libs/pavex_cli/tests/ui_tests/blueprint/router/invalid_paths/expectations/stderr.txt @@ -1,5 +1,5 @@ ERROR: - Γ— You can only register one route parameter per each path segment. + Γ— You can only register one path parameter per each path segment. β”‚ β”‚ ╭─[src/lib.rs:12:1] β”‚ 12 β”‚ let mut bp = Blueprint::new(); @@ -33,8 +33,8 @@ β”‚ ╰──── ERROR: - Γ— All route parameters must be named. You can't use anonymous parameters - β”‚ like `:` or `*`. + Γ— All path parameters must be named. You can't use anonymous parameters like + β”‚ `:` or `*`. β”‚ β”‚ ╭─[src/lib.rs:18:1] β”‚ 18 β”‚ // Unnamed parameter diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/control_flow/you_can_consume_a_non_cloneable_type_from_two_different_control_flow_branches/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/control_flow/you_can_consume_a_non_cloneable_type_from_two_different_control_flow_branches/expectations/app.rs index 28e5ae788..2448e8fbb 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/control_flow/you_can_consume_a_non_cloneable_type_from_two_different_control_flow_branches/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/control_flow/you_can_consume_a_non_cloneable_type_from_two_different_control_flow_branches/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/diamond/diamond_can_be_solved_if_type_is_copy/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/diamond/diamond_can_be_solved_if_type_is_copy/expectations/app.rs index 9ae283844..932c47cab 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/diamond/diamond_can_be_solved_if_type_is_copy/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/diamond/diamond_can_be_solved_if_type_is_copy/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/diamond/diamond_can_be_solved_if_we_can_clone/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/diamond/diamond_can_be_solved_if_we_can_clone/expectations/app.rs index 5dc9726c6..eb7cdc566 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/diamond/diamond_can_be_solved_if_we_can_clone/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/diamond/diamond_can_be_solved_if_we_can_clone/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/expectations/app.rs index 2cf2acfab..f4a494d26 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { @@ -67,9 +67,9 @@ async fn route_request( } pub mod route_0 { pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = as core::clone::Clone>::clone(&v0); diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/expectations/diagnostics.dot b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/expectations/diagnostics.dot index 5dc09793f..a9c9411b0 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/expectations/diagnostics.dot +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/expectations/diagnostics.dot @@ -1,10 +1,10 @@ digraph "GET /home - 0" { 0 [ label = "app::handler(app::B, app::C) -> pavex::response::Response"] - 1 [ label = "app::c(pavex::request::route::RawRouteParams<'_, '_>) -> app::C"] - 2 [ label = "pavex::request::route::RawRouteParams<'server, 'request>"] - 3 [ label = "app::b(pavex::request::route::RawRouteParams<'_, '_>) -> app::B"] + 1 [ label = "app::c(pavex::request::path::RawPathParams<'_, '_>) -> app::C"] + 2 [ label = "pavex::request::path::RawPathParams<'server, 'request>"] + 3 [ label = "app::b(pavex::request::path::RawPathParams<'_, '_>) -> app::B"] 4 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] - 5 [ label = " as core::clone::Clone>::clone(&pavex::request::route::RawRouteParams<'server, 'request>) -> pavex::request::route::RawRouteParams<'server, 'request>"] + 5 [ label = " as core::clone::Clone>::clone(&pavex::request::path::RawPathParams<'server, 'request>) -> pavex::request::path::RawPathParams<'server, 'request>"] 1 -> 0 [ ] 3 -> 0 [ ] 2 -> 3 [ ] diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/lib.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/lib.rs index 7d4688e7b..ed11b8979 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/lib.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_framework_type_can_be_moved_twice/lib.rs @@ -1,23 +1,23 @@ use std::path::PathBuf; -use pavex::f; use pavex::blueprint::{ constructor::{CloningStrategy, Lifecycle}, router::GET, Blueprint, }; -use pavex::request::route::RawRouteParams; +use pavex::f; +use pavex::request::path::RawPathParams; use pavex::response::Response; // The call graph looks like this: // -// RawRouteParams +// RawPathParams // / \ // B C // \ / // handler // -// `RawRouteParams` is a framework-provided type that can be cloned if necessary. +// `RawPathParams` is a framework-provided type that can be cloned if necessary. // It is moved twice here. // Pavex should detect this and insert a `Clone` invocation. @@ -25,11 +25,11 @@ pub struct B; pub struct C; -pub fn b(_p: RawRouteParams) -> B { +pub fn b(_p: RawPathParams) -> B { todo!() } -pub fn c(_p: RawRouteParams) -> C { +pub fn c(_p: RawPathParams) -> C { todo!() } diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_input_type_can_be_moved_twice/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_input_type_can_be_moved_twice/expectations/app.rs index c73529ba5..d8f515dbf 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_input_type_can_be_moved_twice/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_input_type_can_be_moved_twice/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_type_can_be_moved_twice/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_type_can_be_moved_twice/expectations/app.rs index f826492a6..8f06beb99 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_type_can_be_moved_twice/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_clonable_type_can_be_moved_twice/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_copy_type_can_be_moved_twice/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_copy_type_can_be_moved_twice/expectations/app.rs index 609144d9a..6781971c5 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_copy_type_can_be_moved_twice/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/multiple_consumers/a_copy_type_can_be_moved_twice/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/transitive_borrows/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/transitive_borrows/expectations/app.rs index 7f68b7c1a..098769994 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/transitive_borrows/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/transitive_borrows/expectations/app.rs @@ -62,7 +62,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route.params.into(); + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route.params.into(); match route_id { 0u32 => match &request_head.method { &pavex::http::Method::GET => route_0::handler().await, diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/expectations/app.rs index ce90221c3..4673539f0 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { @@ -67,9 +67,9 @@ async fn route_request( } pub mod route_0 { pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = as core::clone::Clone>::clone(&v0); diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/expectations/diagnostics.dot b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/expectations/diagnostics.dot index a6aeb46e4..47c4dcd3e 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/expectations/diagnostics.dot +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/expectations/diagnostics.dot @@ -1,9 +1,9 @@ digraph "GET /home - 0" { - 0 [ label = "app::handler(&pavex::request::route::RawRouteParams<'_, '_>, app::B) -> pavex::response::Response"] - 1 [ label = "app::b(pavex::request::route::RawRouteParams<'_, '_>) -> app::B"] - 2 [ label = "pavex::request::route::RawRouteParams<'server, 'request>"] + 0 [ label = "app::handler(&pavex::request::path::RawPathParams<'_, '_>, app::B) -> pavex::response::Response"] + 1 [ label = "app::b(pavex::request::path::RawPathParams<'_, '_>) -> app::B"] + 2 [ label = "pavex::request::path::RawPathParams<'server, 'request>"] 3 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] - 4 [ label = " as core::clone::Clone>::clone(&pavex::request::route::RawRouteParams<'server, 'request>) -> pavex::request::route::RawRouteParams<'server, 'request>"] + 4 [ label = " as core::clone::Clone>::clone(&pavex::request::path::RawPathParams<'server, 'request>) -> pavex::request::path::RawPathParams<'server, 'request>"] 1 -> 0 [ ] 2 -> 0 [ label = "&"] 0 -> 3 [ ] diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/lib.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/lib.rs index e93210d7b..599cd24bd 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/lib.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_framework_type_is_clonable/lib.rs @@ -1,34 +1,34 @@ use std::path::PathBuf; -use pavex::f; use pavex::blueprint::{ constructor::{CloningStrategy, Lifecycle}, router::GET, Blueprint, }; -use pavex::request::route::RawRouteParams; +use pavex::f; +use pavex::request::path::RawPathParams; use pavex::response::Response; // The call graph looks like this: // -// RawRouteParams +// RawPathParams // / \ // B |& // \ | // handler // -// `RawRouteParams` is a framework built-in type. -// `RawRouteParams` cannot be borrowed by `handler` after it has been moved to construct `B`. -// `RawRouteParams` is cloneable though! -// Pavex should detect this and clone `RawRouteParams` before calling `B`'s constructor. +// `RawPathParams` is a framework built-in type. +// `RawPathParams` cannot be borrowed by `handler` after it has been moved to construct `B`. +// `RawPathParams` is cloneable though! +// Pavex should detect this and clone `RawPathParams` before calling `B`'s constructor. pub struct B; -pub fn b(_p: RawRouteParams) -> B { +pub fn b(_p: RawPathParams) -> B { todo!() } -pub fn handler(_p: &RawRouteParams, _b: B) -> Response { +pub fn handler(_p: &RawPathParams, _b: B) -> Response { todo!() } diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_input_type_is_clonable/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_input_type_is_clonable/expectations/app.rs index dd1285909..8ec76c32a 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_input_type_is_clonable/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_input_type_is_clonable/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_type_is_clonable/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_type_is_clonable/expectations/app.rs index 7b66c12f6..71ba939d8 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_type_is_clonable/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_type_is_clonable/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_type_is_copy/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_type_is_copy/expectations/app.rs index 62fa756fe..56d3af227 100644 --- a/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_type_is_copy/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/borrow_checker/triangle/triangle_can_be_solved_if_type_is_copy/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/dependency_injection/clone_nodes_are_only_added_where_needed/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/dependency_injection/clone_nodes_are_only_added_where_needed/expectations/app.rs index b1311fca8..51722d288 100644 --- a/libs/pavex_cli/tests/ui_tests/dependency_injection/clone_nodes_are_only_added_where_needed/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/dependency_injection/clone_nodes_are_only_added_where_needed/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -52,7 +52,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/dependency_injection/references_to_constructible_types_are_allowed/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/dependency_injection/references_to_constructible_types_are_allowed/expectations/app.rs index bf6def4f1..906f7fa20 100644 --- a/libs/pavex_cli/tests/ui_tests/dependency_injection/references_to_constructible_types_are_allowed/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/dependency_injection/references_to_constructible_types_are_allowed/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/middlewares/next_handles_lifetimes/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/middlewares/next_handles_lifetimes/expectations/app.rs index 8fbc54cf2..737b8f56e 100644 --- a/libs/pavex_cli/tests/ui_tests/middlewares/next_handles_lifetimes/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/middlewares/next_handles_lifetimes/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/expectations/app.rs similarity index 87% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/expectations/app.rs rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/expectations/app.rs index aa5a83e04..4d7d8640f 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { @@ -93,14 +93,14 @@ async fn route_request( } pub mod route_0 { pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -115,14 +115,14 @@ pub mod route_0 { } pub mod route_1 { pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( @@ -137,14 +137,14 @@ pub mod route_1 { } pub mod route_2 { pub async fn handler( - v0: pavex::request::route::RawRouteParams<'_, '_>, + v0: pavex::request::path::RawPathParams<'_, '_>, ) -> pavex::response::Response { - let v1 = pavex::request::route::RouteParams::extract(v0); + let v1 = pavex::request::path::PathParams::extract(v0); let v2 = match v1 { Ok(ok) => ok, Err(v2) => { return { - let v3 = pavex::request::route::errors::ExtractRouteParamsError::into_response( + let v3 = pavex::request::path::errors::ExtractPathParamsError::into_response( &v2, ); ::into_response( diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/expectations/diagnostics.dot b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/expectations/diagnostics.dot similarity index 51% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/expectations/diagnostics.dot rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/expectations/diagnostics.dot index 33db0066c..67792f226 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/expectations/diagnostics.dot +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/expectations/diagnostics.dot @@ -1,11 +1,11 @@ digraph "GET /home/:home_id - 0" { - 0 [ label = "app::get_home(pavex::request::route::RouteParams) -> pavex::response::Response"] - 1 [ label = "core::prelude::rust_2015::Result, pavex::request::route::errors::ExtractRouteParamsError> -> pavex::request::route::RouteParams"] - 2 [ label = "pavex::request::route::RouteParams::extract(pavex::request::route::RawRouteParams<'server, 'request>) -> core::prelude::rust_2015::Result, pavex::request::route::errors::ExtractRouteParamsError>"] - 3 [ label = "pavex::request::route::RawRouteParams<'server, 'request>"] + 0 [ label = "app::get_home(pavex::request::path::PathParams) -> pavex::response::Response"] + 1 [ label = "core::prelude::rust_2015::Result, pavex::request::path::errors::ExtractPathParamsError> -> pavex::request::path::PathParams"] + 2 [ label = "pavex::request::path::PathParams::extract(pavex::request::path::RawPathParams<'server, 'request>) -> core::prelude::rust_2015::Result, pavex::request::path::errors::ExtractPathParamsError>"] + 3 [ label = "pavex::request::path::RawPathParams<'server, 'request>"] 4 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] - 5 [ label = "core::prelude::rust_2015::Result, pavex::request::route::errors::ExtractRouteParamsError> -> pavex::request::route::errors::ExtractRouteParamsError"] - 6 [ label = "pavex::request::route::errors::ExtractRouteParamsError::into_response(&pavex::request::route::errors::ExtractRouteParamsError) -> pavex::response::Response"] + 5 [ label = "core::prelude::rust_2015::Result, pavex::request::path::errors::ExtractPathParamsError> -> pavex::request::path::errors::ExtractPathParamsError"] + 6 [ label = "pavex::request::path::errors::ExtractPathParamsError::into_response(&pavex::request::path::errors::ExtractPathParamsError) -> pavex::response::Response"] 7 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] 8 [ label = "`match`"] 1 -> 0 [ ] @@ -27,13 +27,13 @@ digraph "* /home/:home_id - 0" { } digraph "GET /home/:home_id/room/:room_id - 0" { - 0 [ label = "app::get_room(pavex::request::route::RouteParams) -> pavex::response::Response"] - 1 [ label = "core::prelude::rust_2015::Result, pavex::request::route::errors::ExtractRouteParamsError> -> pavex::request::route::RouteParams"] - 2 [ label = "pavex::request::route::RouteParams::extract(pavex::request::route::RawRouteParams<'server, 'request>) -> core::prelude::rust_2015::Result, pavex::request::route::errors::ExtractRouteParamsError>"] - 3 [ label = "pavex::request::route::RawRouteParams<'server, 'request>"] + 0 [ label = "app::get_room(pavex::request::path::PathParams) -> pavex::response::Response"] + 1 [ label = "core::prelude::rust_2015::Result, pavex::request::path::errors::ExtractPathParamsError> -> pavex::request::path::PathParams"] + 2 [ label = "pavex::request::path::PathParams::extract(pavex::request::path::RawPathParams<'server, 'request>) -> core::prelude::rust_2015::Result, pavex::request::path::errors::ExtractPathParamsError>"] + 3 [ label = "pavex::request::path::RawPathParams<'server, 'request>"] 4 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] - 5 [ label = "core::prelude::rust_2015::Result, pavex::request::route::errors::ExtractRouteParamsError> -> pavex::request::route::errors::ExtractRouteParamsError"] - 6 [ label = "pavex::request::route::errors::ExtractRouteParamsError::into_response(&pavex::request::route::errors::ExtractRouteParamsError) -> pavex::response::Response"] + 5 [ label = "core::prelude::rust_2015::Result, pavex::request::path::errors::ExtractPathParamsError> -> pavex::request::path::errors::ExtractPathParamsError"] + 6 [ label = "pavex::request::path::errors::ExtractPathParamsError::into_response(&pavex::request::path::errors::ExtractPathParamsError) -> pavex::response::Response"] 7 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] 8 [ label = "`match`"] 1 -> 0 [ ] @@ -55,13 +55,13 @@ digraph "* /home/:home_id/room/:room_id - 0" { } digraph "GET /town/*town - 0" { - 0 [ label = "app::get_town(pavex::request::route::RouteParams>) -> pavex::response::Response"] - 1 [ label = "core::prelude::rust_2015::Result>, pavex::request::route::errors::ExtractRouteParamsError> -> pavex::request::route::RouteParams>"] - 2 [ label = "pavex::request::route::RouteParams::extract(pavex::request::route::RawRouteParams<'server, 'request>) -> core::prelude::rust_2015::Result>, pavex::request::route::errors::ExtractRouteParamsError>"] - 3 [ label = "pavex::request::route::RawRouteParams<'server, 'request>"] + 0 [ label = "app::get_town(pavex::request::path::PathParams>) -> pavex::response::Response"] + 1 [ label = "core::prelude::rust_2015::Result>, pavex::request::path::errors::ExtractPathParamsError> -> pavex::request::path::PathParams>"] + 2 [ label = "pavex::request::path::PathParams::extract(pavex::request::path::RawPathParams<'server, 'request>) -> core::prelude::rust_2015::Result>, pavex::request::path::errors::ExtractPathParamsError>"] + 3 [ label = "pavex::request::path::RawPathParams<'server, 'request>"] 4 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] - 5 [ label = "core::prelude::rust_2015::Result>, pavex::request::route::errors::ExtractRouteParamsError> -> pavex::request::route::errors::ExtractRouteParamsError"] - 6 [ label = "pavex::request::route::errors::ExtractRouteParamsError::into_response(&pavex::request::route::errors::ExtractRouteParamsError) -> pavex::response::Response"] + 5 [ label = "core::prelude::rust_2015::Result>, pavex::request::path::errors::ExtractPathParamsError> -> pavex::request::path::errors::ExtractPathParamsError"] + 6 [ label = "pavex::request::path::errors::ExtractPathParamsError::into_response(&pavex::request::path::errors::ExtractPathParamsError) -> pavex::response::Response"] 7 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] 8 [ label = "`match`"] 1 -> 0 [ ] diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/lib.rs b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/lib.rs similarity index 58% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/lib.rs rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/lib.rs index 733b04287..df14d3212 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/lib.rs +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/lib.rs @@ -1,46 +1,44 @@ use pavex::blueprint::{constructor::Lifecycle, router::GET, Blueprint}; use pavex::f; -use pavex::{request::route::RouteParams, response::Response}; +use pavex::{request::path::PathParams, response::Response}; -#[RouteParams] -pub struct HomeRouteParams { +#[PathParams] +pub struct HomePathParams { pub home_id: u32, } -pub fn get_home( - RouteParams(HomeRouteParams { home_id }): RouteParams, -) -> Response { +pub fn get_home(PathParams(HomePathParams { home_id }): PathParams) -> Response { Response::ok().set_typed_body(format!("{}", home_id)) } -#[RouteParams] -pub struct RoomRouteParams { +#[PathParams] +pub struct RoomPathParams { pub home_id: u32, // This is not a valid type for a route parameter pub room_id: Vec, } -pub fn get_room(params: RouteParams) -> Response { +pub fn get_room(params: PathParams) -> Response { Response::ok().set_typed_body(format!("{}", params.0.home_id)) } -#[RouteParams] -pub struct TownRouteParams<'a> { +#[PathParams] +pub struct TownPathParams<'a> { pub town: std::borrow::Cow<'a, str>, } -pub fn get_town(params: RouteParams>) -> Response { +pub fn get_town(params: PathParams>) -> Response { Response::ok().set_typed_body(format!("{}", params.0.town)) } pub fn blueprint() -> Blueprint { let mut bp = Blueprint::new(); bp.constructor( - f!(pavex::request::route::RouteParams::extract), + f!(pavex::request::path::PathParams::extract), Lifecycle::RequestScoped, ) .error_handler(f!( - pavex::request::route::errors::ExtractRouteParamsError::into_response + pavex::request::path::errors::ExtractPathParamsError::into_response )); bp.route(GET, "/home/:home_id", f!(crate::get_home)); bp.route(GET, "/home/:home_id/room/:room_id", f!(crate::get_room)); diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/test.rs b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/test.rs similarity index 95% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/test.rs rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/test.rs index 6364f2758..b395f7d93 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/test.rs +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/test.rs @@ -26,7 +26,7 @@ async fn spawn_test_server() -> u16 { } #[tokio::test] -async fn route_parameter_extraction_works() { +async fn path_parameter_extraction_works() { let port = spawn_test_server().await; let response = reqwest::get(&format!("http://localhost:{}/home/123", port)) .await @@ -74,7 +74,7 @@ async fn catch_all_match_cannot_be_empty() { } #[tokio::test] -async fn route_parameter_has_the_wrong_type() { +async fn path_parameter_has_the_wrong_type() { let port = spawn_test_server().await; let response = reqwest::get(&format!("http://localhost:{}/home/abc", port)) .await @@ -88,7 +88,7 @@ async fn route_parameter_has_the_wrong_type() { } #[tokio::test] -async fn route_parameter_is_invalid_ut8() { +async fn path_parameter_is_invalid_ut8() { let port = spawn_test_server().await; let response = reqwest::get(&format!("http://localhost:{}/home/%DE~%C7%1FY", port)) .await @@ -102,7 +102,7 @@ async fn route_parameter_is_invalid_ut8() { } #[tokio::test] -async fn route_parameter_is_invalid_type() { +async fn path_parameter_is_invalid_type() { let port = spawn_test_server().await; let response = reqwest::get(&format!("http://localhost:{}/home/123/room/123", port)) .await @@ -117,7 +117,7 @@ async fn route_parameter_is_invalid_type() { } #[tokio::test] -async fn route_parameters_cannot_be_empty() { +async fn path_parameters_cannot_be_empty() { let port = spawn_test_server().await; // This does not match `/home/:home_id` because the `home_id` parameter is empty. // There are no handlers registered for `/home` so this should return a 404. diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/test_config.toml b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/test_config.toml similarity index 79% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/test_config.toml rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/test_config.toml index ff7632fb8..3f9740c75 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_happy_path/test_config.toml +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_happy_path/test_config.toml @@ -1,4 +1,4 @@ -description = "Pavex can extract route parameters" +description = "Pavex can extract path parameters" [expectations] codegen = "pass" diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/expectations/stderr.txt b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/expectations/stderr.txt similarity index 63% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/expectations/stderr.txt rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/expectations/stderr.txt index bf0b4064d..28a58a722 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/expectations/stderr.txt +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/expectations/stderr.txt @@ -1,55 +1,54 @@ ERROR: - Γ— `app::missing_one` is trying to extract route parameters using - β”‚ `RouteParams`. + Γ— `app::missing_one` is trying to extract path parameters using + β”‚ `PathParams`. β”‚ Every struct field in `app::MissingOne` must be named after one of the β”‚ route parameters that appear in `/a/:x`: β”‚ - `x` β”‚ - β”‚ There is no route parameter named `y`, but there is a struct field named + β”‚ There is no path parameter named `y`, but there is a struct field named β”‚ `y` in `app::MissingOne`. This is going to cause a runtime error! β”‚ β”‚ ╭─[src/lib.rs:44:1] β”‚ 44 β”‚ )); β”‚ 45 β”‚ bp.route(GET, "/a/:x", f!(crate::missing_one)); β”‚ Β·  ───────────┬────────── - β”‚ Β· The request handler asking for `RouteParams` + β”‚ Β· The request handler asking for `PathParams` β”‚ 46 β”‚ bp.route(GET, "/b/:x", f!(crate::missing_two)); β”‚ ╰──── - β”‚  help: Remove or rename the fields that do not map to a valid route + β”‚  help: Remove or rename the fields that do not map to a valid path β”‚ parameter. ERROR: - Γ— `app::missing_two` is trying to extract route parameters using - β”‚ `RouteParams`. + Γ— `app::missing_two` is trying to extract path parameters using + β”‚ `PathParams`. β”‚ Every struct field in `app::MissingTwo` must be named after one of the β”‚ route parameters that appear in `/b/:x`: β”‚ - `x` β”‚ - β”‚ There are no route parameters named `y` or `z`, but they appear as field + β”‚ There are no path parameters named `y` or `z`, but they appear as field β”‚ names in `app::MissingTwo`. This is going to cause a runtime error! β”‚ β”‚ ╭─[src/lib.rs:45:1] β”‚ 45 β”‚ bp.route(GET, "/a/:x", f!(crate::missing_one)); β”‚ 46 β”‚ bp.route(GET, "/b/:x", f!(crate::missing_two)); β”‚ Β·  ───────────┬────────── - β”‚ Β· The request handler asking for `RouteParams` - β”‚ 47 β”‚ bp.route(GET, "/c", f!(crate::no_route_params)); + β”‚ Β· The request handler asking for `PathParams` + β”‚ 47 β”‚ bp.route(GET, "/c", f!(crate::no_path_params)); β”‚ ╰──── - β”‚  help: Remove or rename the fields that do not map to a valid route + β”‚  help: Remove or rename the fields that do not map to a valid path β”‚ parameter. ERROR: - Γ— `app::no_route_params` is trying to extract route parameters using - β”‚ `RouteParams`. - β”‚ But there are no route parameters in `/c`, the corresponding route - β”‚ template! + Γ— `app::no_path_params` is trying to extract path parameters using + β”‚ `PathParams`. + β”‚ But there are no path parameters in `/c`, the corresponding path pattern! β”‚ β”‚ ╭─[src/lib.rs:46:1] β”‚ 46 β”‚ bp.route(GET, "/b/:x", f!(crate::missing_two)); - β”‚ 47 β”‚ bp.route(GET, "/c", f!(crate::no_route_params)); - β”‚ Β·  ─────────────┬──────────── - β”‚ Β· The request handler asking for `RouteParams` + β”‚ 47 β”‚ bp.route(GET, "/c", f!(crate::no_path_params)); + β”‚ Β·  ────────────┬──────────── + β”‚ Β· The request handler asking for `PathParams` β”‚ 48 β”‚ bp β”‚ ╰──── - β”‚  help: Stop trying to extract route parameters, or add them to the route - β”‚ template! \ No newline at end of file + β”‚  help: Stop trying to extract path parameters, or add them to the path + β”‚ pattern! \ No newline at end of file diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/lib.rs b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/lib.rs similarity index 50% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/lib.rs rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/lib.rs index 1fc3f2aa2..ba220a4ce 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/lib.rs +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/lib.rs @@ -1,49 +1,49 @@ use pavex::blueprint::{constructor::Lifecycle, router::GET, Blueprint}; use pavex::f; -use pavex::{http::StatusCode, request::route::RouteParams}; +use pavex::{http::StatusCode, request::path::PathParams}; -#[RouteParams] +#[PathParams] pub struct MissingOne { x: u32, y: u32, } -pub fn missing_one(params: RouteParams) -> StatusCode { +pub fn missing_one(params: PathParams) -> StatusCode { todo!() } -#[RouteParams] +#[PathParams] pub struct MissingTwo { x: u32, y: u32, z: u32, } -pub fn missing_two(params: RouteParams) -> StatusCode { +pub fn missing_two(params: PathParams) -> StatusCode { todo!() } -#[RouteParams] -pub struct NoRouteParams { +#[PathParams] +pub struct NoPathParams { x: u32, y: u32, } -pub fn no_route_params(params: RouteParams) -> StatusCode { +pub fn no_path_params(params: PathParams) -> StatusCode { todo!() } pub fn blueprint() -> Blueprint { let mut bp = Blueprint::new(); bp.constructor( - f!(pavex::request::route::RouteParams::extract), + f!(pavex::request::path::PathParams::extract), Lifecycle::RequestScoped, ) .error_handler(f!( - pavex::request::route::errors::ExtractRouteParamsError::into_response + pavex::request::path::errors::ExtractPathParamsError::into_response )); bp.route(GET, "/a/:x", f!(crate::missing_one)); bp.route(GET, "/b/:x", f!(crate::missing_two)); - bp.route(GET, "/c", f!(crate::no_route_params)); + bp.route(GET, "/c", f!(crate::no_path_params)); bp } diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/test_config.toml b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/test_config.toml similarity index 67% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/test_config.toml rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/test_config.toml index c9bae443e..502ab320a 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_non_existing_fields/test_config.toml +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_non_existing_fields/test_config.toml @@ -1,4 +1,4 @@ -description = "Pavex will detect at compile-time if you are trying to extract a route parameter that does not exist in the route definition." +description = "Pavex will detect at compile-time if you are trying to extract a path parameter that does not exist in the route definition." [expectations] codegen = "fail" diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/expectations/stderr.txt b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/expectations/stderr.txt similarity index 66% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/expectations/stderr.txt rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/expectations/stderr.txt index fdd366eb1..966859be6 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/expectations/stderr.txt +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/expectations/stderr.txt @@ -1,8 +1,8 @@ ERROR: - Γ— Route parameters must be extracted using a plain struct with named fields, - β”‚ where the name of each field matches one of the route parameters specified + Γ— Path parameters must be extracted using a plain struct with named fields, + β”‚ where the name of each field matches one of the path parameters specified β”‚ in the route for the respective request handler. - β”‚ `app::primitive` is trying to extract `RouteParams`, but `u32` is a + β”‚ `app::primitive` is trying to extract `PathParams`, but `u32` is a β”‚ primitive, not a plain struct type. I don't support this: the extraction β”‚ would fail at runtime, when trying to process an incoming request. β”‚ @@ -10,17 +10,17 @@ β”‚ 61 β”‚ )); β”‚ 62 β”‚ bp.route(GET, "/a/:x", f!(crate::primitive)); β”‚ Β·  ──────────┬───────── - β”‚ Β· The request handler asking for `RouteParams` + β”‚ Β· The request handler asking for `PathParams` β”‚ 63 β”‚ bp.route(GET, "/b/:x/:y", f!(crate::tuple)); β”‚ ╰──── - β”‚  help: Use a plain struct with named fields to extract route parameters. - β”‚ Check out `RouteParams`' documentation for all the details! + β”‚  help: Use a plain struct with named fields to extract path parameters. + β”‚ Check out `PathParams`' documentation for all the details! ERROR: - Γ— Route parameters must be extracted using a plain struct with named fields, - β”‚ where the name of each field matches one of the route parameters specified + Γ— Path parameters must be extracted using a plain struct with named fields, + β”‚ where the name of each field matches one of the path parameters specified β”‚ in the route for the respective request handler. - β”‚ `app::tuple` is trying to extract `RouteParams<(u32, u32)>`, but `(u32, + β”‚ `app::tuple` is trying to extract `PathParams<(u32, u32)>`, but `(u32, β”‚ u32)` is a tuple, not a plain struct type. I don't support this: the β”‚ extraction would fail at runtime, when trying to process an incoming β”‚ request. @@ -29,17 +29,17 @@ β”‚ 62 β”‚ bp.route(GET, "/a/:x", f!(crate::primitive)); β”‚ 63 β”‚ bp.route(GET, "/b/:x/:y", f!(crate::tuple)); β”‚ Β·  ────────┬─────── - β”‚ Β· The request handler asking for `RouteParams<(u32, u32)>` + β”‚ Β· The request handler asking for `PathParams<(u32, u32)>` β”‚ 64 β”‚ bp.route(GET, "/c/:x/:z", f!(crate::slice_ref)); β”‚ ╰──── - β”‚  help: Use a plain struct with named fields to extract route parameters. - β”‚ Check out `RouteParams`' documentation for all the details! + β”‚  help: Use a plain struct with named fields to extract path parameters. + β”‚ Check out `PathParams`' documentation for all the details! ERROR: - Γ— Route parameters must be extracted using a plain struct with named fields, - β”‚ where the name of each field matches one of the route parameters specified + Γ— Path parameters must be extracted using a plain struct with named fields, + β”‚ where the name of each field matches one of the path parameters specified β”‚ in the route for the respective request handler. - β”‚ `app::slice_ref` is trying to extract `RouteParams<&[u32]>`, but `&[u32]` + β”‚ `app::slice_ref` is trying to extract `PathParams<&[u32]>`, but `&[u32]` β”‚ is a reference, not a plain struct type. I don't support this: the β”‚ extraction would fail at runtime, when trying to process an incoming β”‚ request. @@ -48,18 +48,18 @@ β”‚ 63 β”‚ bp.route(GET, "/b/:x/:y", f!(crate::tuple)); β”‚ 64 β”‚ bp.route(GET, "/c/:x/:z", f!(crate::slice_ref)); β”‚ Β·  ──────────┬───────── - β”‚ Β· The request handler asking for `RouteParams<&[u32]>` + β”‚ Β· The request handler asking for `PathParams<&[u32]>` β”‚ 65 β”‚ bp.route(GET, "/d/:x/:y", f!(crate::reference::)); β”‚ ╰──── - β”‚  help: Use a plain struct with named fields to extract route parameters. - β”‚ Check out `RouteParams`' documentation for all the details! + β”‚  help: Use a plain struct with named fields to extract path parameters. + β”‚ Check out `PathParams`' documentation for all the details! ERROR: - Γ— Route parameters must be extracted using a plain struct with named fields, - β”‚ where the name of each field matches one of the route parameters specified + Γ— Path parameters must be extracted using a plain struct with named fields, + β”‚ where the name of each field matches one of the path parameters specified β”‚ in the route for the respective request handler. β”‚ `app::reference::` is trying to extract - β”‚ `RouteParams<&app::MyStruct>`, but `&app::MyStruct` is a reference, not + β”‚ `PathParams<&app::MyStruct>`, but `&app::MyStruct` is a reference, not β”‚ a plain struct type. I don't support this: the extraction would fail at β”‚ runtime, when trying to process an incoming request. β”‚ @@ -67,17 +67,17 @@ β”‚ 64 β”‚ bp.route(GET, "/c/:x/:z", f!(crate::slice_ref)); β”‚ 65 β”‚ bp.route(GET, "/d/:x/:y", f!(crate::reference::)); β”‚ Β·  ───────────────────┬─────────────────── - β”‚ Β· The request handler asking for `RouteParams<&app::MyStruct>` + β”‚ Β· The request handler asking for `PathParams<&app::MyStruct>` β”‚ 66 β”‚ bp.route(GET, "/e/:x/:y", f!(crate::enum_)); β”‚ ╰──── - β”‚  help: Use a plain struct with named fields to extract route parameters. - β”‚ Check out `RouteParams`' documentation for all the details! + β”‚  help: Use a plain struct with named fields to extract path parameters. + β”‚ Check out `PathParams`' documentation for all the details! ERROR: - Γ— Route parameters must be extracted using a plain struct with named fields, - β”‚ where the name of each field matches one of the route parameters specified + Γ— Path parameters must be extracted using a plain struct with named fields, + β”‚ where the name of each field matches one of the path parameters specified β”‚ in the route for the respective request handler. - β”‚ `app::enum_` is trying to extract `RouteParams`, but + β”‚ `app::enum_` is trying to extract `PathParams`, but β”‚ `app::MyEnum` is an enum, not a plain struct type. I don't support this: β”‚ the extraction would fail at runtime, when trying to process an incoming β”‚ request. @@ -86,17 +86,17 @@ β”‚ 65 β”‚ bp.route(GET, "/d/:x/:y", f!(crate::reference::)); β”‚ 66 β”‚ bp.route(GET, "/e/:x/:y", f!(crate::enum_)); β”‚ Β·  ────────┬─────── - β”‚ Β· The request handler asking for `RouteParams` + β”‚ Β· The request handler asking for `PathParams` β”‚ 67 β”‚ bp.route(GET, "/f/:x/:y", f!(crate::tuple_struct)); β”‚ ╰──── - β”‚  help: Use a plain struct with named fields to extract route parameters. - β”‚ Check out `RouteParams`' documentation for all the details! + β”‚  help: Use a plain struct with named fields to extract path parameters. + β”‚ Check out `PathParams`' documentation for all the details! ERROR: - Γ— Route parameters must be extracted using a plain struct with named fields, - β”‚ where the name of each field matches one of the route parameters specified + Γ— Path parameters must be extracted using a plain struct with named fields, + β”‚ where the name of each field matches one of the path parameters specified β”‚ in the route for the respective request handler. - β”‚ `app::tuple_struct` is trying to extract `RouteParams`, + β”‚ `app::tuple_struct` is trying to extract `PathParams`, β”‚ but `app::TupleStruct` is a tuple struct, not a plain struct type. I don't β”‚ support this: the extraction would fail at runtime, when trying to process β”‚ an incoming request. @@ -105,17 +105,17 @@ β”‚ 66 β”‚ bp.route(GET, "/e/:x/:y", f!(crate::enum_)); β”‚ 67 β”‚ bp.route(GET, "/f/:x/:y", f!(crate::tuple_struct)); β”‚ Β·  ───────────┬─────────── - β”‚ Β· The request handler asking for `RouteParams` + β”‚ Β· The request handler asking for `PathParams` β”‚ 68 β”‚ bp.route(GET, "/g/:x/:y", f!(crate::unit_struct)); β”‚ ╰──── - β”‚  help: Use a plain struct with named fields to extract route parameters. - β”‚ Check out `RouteParams`' documentation for all the details! + β”‚  help: Use a plain struct with named fields to extract path parameters. + β”‚ Check out `PathParams`' documentation for all the details! ERROR: - Γ— Route parameters must be extracted using a plain struct with named fields, - β”‚ where the name of each field matches one of the route parameters specified + Γ— Path parameters must be extracted using a plain struct with named fields, + β”‚ where the name of each field matches one of the path parameters specified β”‚ in the route for the respective request handler. - β”‚ `app::unit_struct` is trying to extract `RouteParams`, + β”‚ `app::unit_struct` is trying to extract `PathParams`, β”‚ but `app::UnitStruct` is a struct with no fields (a.k.a. unit struct), not β”‚ a plain struct type. I don't support this: the extraction would fail at β”‚ runtime, when trying to process an incoming request. @@ -124,8 +124,8 @@ β”‚ 67 β”‚ bp.route(GET, "/f/:x/:y", f!(crate::tuple_struct)); β”‚ 68 β”‚ bp.route(GET, "/g/:x/:y", f!(crate::unit_struct)); β”‚ Β·  ───────────┬────────── - β”‚ Β· The request handler asking for `RouteParams` + β”‚ Β· The request handler asking for `PathParams` β”‚ 69 β”‚ bp β”‚ ╰──── - β”‚  help: Use a plain struct with named fields to extract route parameters. - β”‚ Check out `RouteParams`' documentation for all the details! \ No newline at end of file + β”‚  help: Use a plain struct with named fields to extract path parameters. + β”‚ Check out `PathParams`' documentation for all the details! \ No newline at end of file diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/lib.rs b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/lib.rs similarity index 58% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/lib.rs rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/lib.rs index 28ec62977..9a5e6ec14 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/lib.rs +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/lib.rs @@ -1,63 +1,63 @@ use pavex::blueprint::{constructor::Lifecycle, router::GET, Blueprint}; -use pavex::request::route::RouteParams; use pavex::f; use pavex::http::StatusCode; +use pavex::request::path::PathParams; -pub fn tuple(params: RouteParams<(u32, u32)>) -> StatusCode { +pub fn tuple(params: PathParams<(u32, u32)>) -> StatusCode { todo!() } -pub fn primitive(params: RouteParams) -> StatusCode { +pub fn primitive(params: PathParams) -> StatusCode { todo!() } -pub fn slice_ref(params: RouteParams<&[u32]>) -> StatusCode { +pub fn slice_ref(params: PathParams<&[u32]>) -> StatusCode { todo!() } -#[RouteParams] +#[PathParams] pub struct MyStruct { x: u32, y: u32, } -pub fn reference(params: RouteParams<&T>) -> StatusCode { +pub fn reference(params: PathParams<&T>) -> StatusCode { todo!() } -#[RouteParams] +#[PathParams] pub enum MyEnum { A(u32), B, C { x: u32, y: u32 }, } -pub fn enum_(params: RouteParams) -> StatusCode { +pub fn enum_(params: PathParams) -> StatusCode { todo!() } -#[RouteParams] +#[PathParams] pub struct UnitStruct; -pub fn unit_struct(params: RouteParams) -> StatusCode { +pub fn unit_struct(params: PathParams) -> StatusCode { todo!() } -#[RouteParams] +#[PathParams] pub struct TupleStruct(u32, u32); -pub fn tuple_struct(params: RouteParams) -> StatusCode { +pub fn tuple_struct(params: PathParams) -> StatusCode { todo!() } pub fn blueprint() -> Blueprint { let mut bp = Blueprint::new(); bp.constructor( - f!(pavex::request::route::RouteParams::extract), + f!(pavex::request::path::PathParams::extract), Lifecycle::RequestScoped, ) .error_handler(f!( - pavex::request::route::errors::ExtractRouteParamsError::into_response + pavex::request::path::errors::ExtractPathParamsError::into_response )); bp.route(GET, "/a/:x", f!(crate::primitive)); bp.route(GET, "/b/:x/:y", f!(crate::tuple)); diff --git a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/test_config.toml b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/test_config.toml similarity index 52% rename from libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/test_config.toml rename to libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/test_config.toml index 7859c1e7e..dc4a35086 100644 --- a/libs/pavex_cli/tests/ui_tests/route_parameters/route_parameters_unsupported_types/test_config.toml +++ b/libs/pavex_cli/tests/ui_tests/path_parameters/path_parameters_unsupported_types/test_config.toml @@ -1,4 +1,4 @@ -description = "Pavex can only extract route parameters using a struct with named fields" +description = "Pavex can only extract path parameters using a struct with named fields" [expectations] codegen = "fail" diff --git a/libs/pavex_cli/tests/ui_tests/reflection/arc_singletons_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/arc_singletons_are_supported/expectations/app.rs index b19c79775..e23d859b7 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/arc_singletons_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/arc_singletons_are_supported/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/common_response_types_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/common_response_types_are_supported/expectations/app.rs index 21a433410..be41d4e6d 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/common_response_types_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/common_response_types_are_supported/expectations/app.rs @@ -37,7 +37,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -49,7 +49,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/dependencies_can_register_local_items/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/dependencies_can_register_local_items/expectations/app.rs index 1e28ba5c0..61694bbbe 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/dependencies_can_register_local_items/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/dependencies_can_register_local_items/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/multiple_versions_for_the_same_crate_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/multiple_versions_for_the_same_crate_are_supported/expectations/app.rs index 400a393ad..b9c5348d9 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/multiple_versions_for_the_same_crate_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/multiple_versions_for_the_same_crate_are_supported/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/transitive_dependencies_can_be_renamed/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/transitive_dependencies_can_be_renamed/expectations/app.rs index 2be8b037a..6079840e9 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/transitive_dependencies_can_be_renamed/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/crate_resolution/transitive_dependencies_can_be_renamed/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/generic_handlers_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/generic_handlers_are_supported/expectations/app.rs index 928ea034d..9a4a1ba1d 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/generic_handlers_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/generic_handlers_are_supported/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/generic_parameters_can_come_from_another_crate/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/generic_parameters_can_come_from_another_crate/expectations/app.rs index a471d02b3..bd07bb475 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/generic_parameters_can_come_from_another_crate/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/generic_parameters_can_come_from_another_crate/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/local_glob_reexports_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/local_glob_reexports_are_supported/expectations/app.rs index b4d8cd996..cc21b160f 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/local_glob_reexports_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/local_glob_reexports_are_supported/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/non_static_methods_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/non_static_methods_are_supported/expectations/app.rs index 38e4de0e2..e7907dc12 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/non_static_methods_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/non_static_methods_are_supported/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/pattern_bindings_in_input_parameters_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/pattern_bindings_in_input_parameters_are_supported/expectations/app.rs index da61208fe..77a8df00b 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/pattern_bindings_in_input_parameters_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/pattern_bindings_in_input_parameters_are_supported/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/static_methods_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/static_methods_are_supported/expectations/app.rs index 04c9e0e82..297e5b4cd 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/static_methods_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/static_methods_are_supported/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/trait_methods_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/trait_methods_are_supported/expectations/app.rs index 3ac46d3f0..120871b57 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/trait_methods_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/trait_methods_are_supported/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/trait_methods_with_non_local_generics_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/trait_methods_with_non_local_generics_are_supported/expectations/app.rs index 3791d14ed..c96abe8e8 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/trait_methods_with_non_local_generics_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/trait_methods_with_non_local_generics_are_supported/expectations/app.rs @@ -34,7 +34,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -46,7 +46,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/tuples_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/tuples_are_supported/expectations/app.rs index 523b30d0c..9bc7e658c 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/tuples_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/tuples_are_supported/expectations/app.rs @@ -36,7 +36,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -48,7 +48,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_cli/tests/ui_tests/reflection/type_alias_are_supported/expectations/app.rs b/libs/pavex_cli/tests/ui_tests/reflection/type_alias_are_supported/expectations/app.rs index eae72c54c..a37a659ef 100644 --- a/libs/pavex_cli/tests/ui_tests/reflection/type_alias_are_supported/expectations/app.rs +++ b/libs/pavex_cli/tests/ui_tests/reflection/type_alias_are_supported/expectations/app.rs @@ -41,7 +41,7 @@ async fn route_request( #[allow(unused)] let request_body = pavex::request::body::RawIncomingBody::from(request_body); let request_head: pavex::request::RequestHead = request_head.into(); - let matched_route = match server_state.router.at(&request_head.uri.path()) { + let matched_route = match server_state.router.at(&request_head.target.path()) { Ok(m) => m, Err(_) => { let allowed_methods: pavex::router::AllowedMethods = pavex::router::MethodAllowList::from_iter( @@ -53,7 +53,7 @@ async fn route_request( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavex_macros/src/lib.rs b/libs/pavex_macros/src/lib.rs index 606893e33..1da509c51 100644 --- a/libs/pavex_macros/src/lib.rs +++ b/libs/pavex_macros/src/lib.rs @@ -6,7 +6,7 @@ use syn::{parse_macro_input, Attribute, Data, DeriveInput, Error, GenericParam, #[allow(non_snake_case)] #[proc_macro_attribute] -pub fn RouteParams(_metadata: TokenStream, input: TokenStream) -> TokenStream { +pub fn PathParams(_metadata: TokenStream, input: TokenStream) -> TokenStream { let mut ast = parse_macro_input!(input as DeriveInput); if let Err(mut e) = reject_serde_attributes(&ast) { // We emit both the error AND the original struct. @@ -86,12 +86,12 @@ fn reject_serde_attributes(ast: &DeriveInput) -> Result<(), TokenStream> { /// because we rely on `serde`'s default behaviour to determine, at code-generartion time, /// if the route params can be deserialized from the URL of the incoming request. fn reject_serde_attribute(attr: &Attribute) -> Result<(), TokenStream> { - let err_msg = "`RouteParams` does not support `serde` attributes on the top-level struct or any of its fields.\n\n\ - `RouteParams` takes care of deriving `serde::Serialize` and `serde::Deserialize` for your struct, using the default \ + let err_msg = "`PathParams` does not support `serde` attributes on the top-level struct or any of its fields.\n\n\ + `PathParams` takes care of deriving `serde::Serialize` and `serde::Deserialize` for your struct, using the default \ configuration. This allow Pavex to determine, at code-generation time, if the route params can \ be successfully extracted from the URL of incoming requests for the relevant routes (e.g. do you \ have a named field that doesn't map to any of the registered route parameters?).\n\n\ - If the default `serde` configuration won't work for your case, you should not derive `RouteParams` and \ + If the default `serde` configuration won't work for your case, you should not derive `PathParams` and \ opt instead for implementing `serde::Serialize` and `serde::Deserialize` directly for your struct (either \ manually or using a derive with custom attributes).\nKeep in mind that by going down this route \ you give up compile-time checking of the route parameters!"; diff --git a/libs/pavex_macros/tests/fail/serde_conflict.rs b/libs/pavex_macros/tests/fail/serde_conflict.rs index 94a0abad3..e3bd723a0 100644 --- a/libs/pavex_macros/tests/fail/serde_conflict.rs +++ b/libs/pavex_macros/tests/fail/serde_conflict.rs @@ -1,5 +1,5 @@ #[derive(serde::Deserialize)] -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] #[serde(rename_all = "camelCase")] struct MyStruct { #[serde(rename = "field1")] diff --git a/libs/pavex_macros/tests/fail/serde_conflict_after_route_params_without_attributes.rs b/libs/pavex_macros/tests/fail/serde_conflict_after_route_params_without_attributes.rs index d6a7a7f8d..a8b840477 100644 --- a/libs/pavex_macros/tests/fail/serde_conflict_after_route_params_without_attributes.rs +++ b/libs/pavex_macros/tests/fail/serde_conflict_after_route_params_without_attributes.rs @@ -1,4 +1,4 @@ -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] #[derive(serde::Deserialize)] struct MyStruct { field1: i32, diff --git a/libs/pavex_macros/tests/fail/serde_conflict_before_route_params_without_attributes.rs b/libs/pavex_macros/tests/fail/serde_conflict_before_route_params_without_attributes.rs index 96e50c8bf..001764e9a 100644 --- a/libs/pavex_macros/tests/fail/serde_conflict_before_route_params_without_attributes.rs +++ b/libs/pavex_macros/tests/fail/serde_conflict_before_route_params_without_attributes.rs @@ -1,5 +1,5 @@ #[derive(serde::Deserialize)] -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] struct MyStruct { field1: i32, field2: String, diff --git a/libs/pavex_macros/tests/success/happy.rs b/libs/pavex_macros/tests/success/happy.rs index ec1625f66..2010f2c4b 100644 --- a/libs/pavex_macros/tests/success/happy.rs +++ b/libs/pavex_macros/tests/success/happy.rs @@ -1,39 +1,39 @@ -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] struct SimpleStruct { field1: i32, field2: String, } -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] struct NestedStruct { field1: SimpleStruct, } -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] struct StructWithOneGeneric { field1: T, field2: String, } -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] struct StructWithOneInlineBoundGeneric { field1: T, field2: String, } -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] struct StructWithTwoGenerics { field1: T, field2: S, } -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] struct StructWithOneGenericAndALifetime<'a, S> { field1: &'a str, field2: S, } -#[pavex_macros::RouteParams] +#[pavex_macros::PathParams] struct StructWithTwoLifetimes<'a, 'b: 'a> { field1: &'a str, field2: &'b str, diff --git a/libs/pavexc/src/compiler/analyses/framework_items.rs b/libs/pavexc/src/compiler/analyses/framework_items.rs index 150f648a2..c6b2ed7e9 100644 --- a/libs/pavexc/src/compiler/analyses/framework_items.rs +++ b/libs/pavexc/src/compiler/analyses/framework_items.rs @@ -14,7 +14,7 @@ use crate::{ pub(crate) type FrameworkItemId = u8; /// The set of types that are built into the frameworkβ€”e.g. the incoming request, -/// raw route parameters. +/// raw path parameters. /// /// These types can be used by constructors and handlers even though no constructor /// has been explicitly registered for them by the developer. @@ -63,7 +63,7 @@ impl FrameworkItemDb { }, ); let raw_path_parameters = process_framework_path( - "pavex::request::route::RawRouteParams::<'server, 'request>", + "pavex::request::path::RawPathParams::<'server, 'request>", package_graph, krate_collection, ); @@ -77,7 +77,7 @@ impl FrameworkItemDb { }, ); let matched_route_template = process_framework_path( - "pavex::request::route::MatchedRouteTemplate", + "pavex::request::path::MatchedPathPattern", package_graph, krate_collection, ); @@ -108,12 +108,12 @@ impl FrameworkItemDb { Self { items, id2metadata } } - /// Return the id for the `MatchedRouteTemplate` type. + /// Return the id for the `MatchedPathPattern` type. pub(crate) fn matched_route_template_id() -> FrameworkItemId { 3 } - /// Return the id for the `MatchedRouteTemplate` type. + /// Return the id for the `MatchedPathPattern` type. pub(crate) fn allowed_methods_id() -> FrameworkItemId { 4 } diff --git a/libs/pavexc/src/compiler/analyses/user_components/router.rs b/libs/pavexc/src/compiler/analyses/user_components/router.rs index 18d83bd3c..4e6f514f0 100644 --- a/libs/pavexc/src/compiler/analyses/user_components/router.rs +++ b/libs/pavexc/src/compiler/analyses/user_components/router.rs @@ -806,10 +806,10 @@ fn push_matchit_diagnostic( anyhow!("This route path, `{}`, conflicts with the path of another route you already registered, `{}`.", path, with) } InsertError::TooManyParams => { - anyhow!("You can only register one route parameter per each path segment.") + anyhow!("You can only register one path parameter per each path segment.") } InsertError::UnnamedParam => { - anyhow!("All route parameters must be named. You can't use anonymous parameters like `:` or `*`.") + anyhow!("All path parameters must be named. You can't use anonymous parameters like `:` or `*`.") } InsertError::InvalidCatchAll => { anyhow!("You can only use catch-all parameters at the end of a route path.") diff --git a/libs/pavexc/src/compiler/app.rs b/libs/pavexc/src/compiler/app.rs index 60a2f7f9e..49da2e26a 100644 --- a/libs/pavexc/src/compiler/app.rs +++ b/libs/pavexc/src/compiler/app.rs @@ -30,7 +30,7 @@ use crate::compiler::generated_app::GeneratedApp; use crate::compiler::resolvers::CallableResolutionError; use crate::compiler::traits::{assert_trait_is_implemented, MissingTraitImplementationError}; use crate::compiler::utils::process_framework_path; -use crate::compiler::{codegen, route_parameter_validation}; +use crate::compiler::{codegen, path_parameter_validation}; use crate::diagnostic; use crate::diagnostic::{CompilerDiagnostic, LocationExt, SourceSpanExt}; use crate::language::ResolvedType; @@ -129,7 +129,7 @@ impl App { } handler_pipelines }; - route_parameter_validation::verify_route_parameters( + path_parameter_validation::verify_path_parameters( &router, &handler_id2pipeline, &computation_db, diff --git a/libs/pavexc/src/compiler/codegen.rs b/libs/pavexc/src/compiler/codegen.rs index ae6edbfbe..5563d0180 100644 --- a/libs/pavexc/src/compiler/codegen.rs +++ b/libs/pavexc/src/compiler/codegen.rs @@ -42,7 +42,7 @@ impl CodegenMethodRouter { .chain(std::iter::once(&self.catch_all_pipeline)) } - /// Returns `true` if any of the pipelines in this router needs `MatchedRouteTemplate` + /// Returns `true` if any of the pipelines in this router needs `MatchedPathPattern` /// as input type. pub fn needs_matched_route(&self, framework_items_db: &FrameworkItemDb) -> bool { let matched_route_type = framework_items_db @@ -417,7 +417,7 @@ fn get_request_dispatcher( let matched_route_template = if sub_router.needs_matched_route(framework_items_db) { let path = route_id2path.get_by_left(route_id).unwrap(); quote! { - let matched_route_template = #pavex::request::route::MatchedRouteTemplate::new( + let matched_route_template = #pavex::request::path::MatchedPathPattern::new( #path ); } @@ -463,7 +463,7 @@ fn get_request_dispatcher( ); let unmatched_route = if fallback_codegened_pipeline.needs_matched_route(framework_items_db) { quote! { - let matched_route_template = #pavex::request::route::MatchedRouteTemplate::new("*"); + let matched_route_template = #pavex::request::path::MatchedPathPattern::new("*"); } } else { quote! {} @@ -494,7 +494,7 @@ fn get_request_dispatcher( }; let route_id = matched_route.value; #[allow(unused)] - let url_params: #pavex::request::route::RawRouteParams<'_, '_> = matched_route + let url_params: #pavex::request::path::RawPathParams<'_, '_> = matched_route .params .into(); match route_id { diff --git a/libs/pavexc/src/compiler/mod.rs b/libs/pavexc/src/compiler/mod.rs index 9de4fadd4..d5729362e 100644 --- a/libs/pavexc/src/compiler/mod.rs +++ b/libs/pavexc/src/compiler/mod.rs @@ -10,7 +10,7 @@ mod component; mod computation; mod generated_app; mod interner; +mod path_parameter_validation; mod resolvers; -mod route_parameter_validation; mod traits; mod utils; diff --git a/libs/pavexc/src/compiler/route_parameter_validation.rs b/libs/pavexc/src/compiler/path_parameter_validation.rs similarity index 76% rename from libs/pavexc/src/compiler/route_parameter_validation.rs rename to libs/pavexc/src/compiler/path_parameter_validation.rs index bc12bdc8f..b68954071 100644 --- a/libs/pavexc/src/compiler/route_parameter_validation.rs +++ b/libs/pavexc/src/compiler/path_parameter_validation.rs @@ -1,5 +1,3 @@ -use std::fmt::Write; - use anyhow::anyhow; use guppy::graph::PackageGraph; use indexmap::{IndexMap, IndexSet}; @@ -26,11 +24,11 @@ use crate::utils::comma_separated_list; use super::traits::assert_trait_is_implemented; -/// For each handler, check if route parameters are extracted from the URL of the incoming request. -/// If so, check that the type of the route parameter is a struct with named fields and -/// that each named field maps to a route parameter for the corresponding handler. -#[tracing::instrument(name = "Verify route parameters", skip_all)] -pub(crate) fn verify_route_parameters( +/// For each handler, check if path parameters are extracted from the URL of the incoming request. +/// If so, check that the type of the path parameter is a struct with named fields and +/// that each named field maps to a path parameter for the corresponding handler. +#[tracing::instrument(name = "Verify path parameters", skip_all)] +pub(crate) fn verify_path_parameters( router: &Router, handler_id2pipeline: &IndexMap, computation_db: &ComputationDb, @@ -53,10 +51,10 @@ pub(crate) fn verify_route_parameters( continue; }; - // If `RouteParams` is used, it will appear as a `Compute` node in *at most* one of the + // If `PathParams` is used, it will appear as a `Compute` node in *at most* one of the // call graphs in the processing pipeline for the handler, since it's a `RequestScoped` // component. - let Some((graph, ok_route_params_node_id, ty_)) = + let Some((graph, ok_path_params_node_id, ty_)) = pipeline.graph_iter().find_map(|graph| { let graph = &graph.call_graph; graph @@ -80,7 +78,7 @@ pub(crate) fn verify_route_parameters( let ResolvedType::ResolvedPath(ty_) = &m.output else { return None; }; - if ty_.base_type == vec!["pavex", "request", "route", "RouteParams"] { + if ty_.base_type == vec!["pavex", "request", "path", "PathParams"] { Some((node_id, ty_.clone())) } else { None @@ -102,7 +100,7 @@ pub(crate) fn verify_route_parameters( krate_collection, diagnostics, graph, - ok_route_params_node_id, + ok_path_params_node_id, extracted_type, ) else { continue; @@ -111,7 +109,7 @@ pub(crate) fn verify_route_parameters( unreachable!() }; - // We only want to check alignment between struct fields and the route parameters in the + // We only want to check alignment between struct fields and the path parameters in the // template if the struct implements `StructuralDeserialize`, our marker trait that stands // for "this struct implements serde::Deserialize using a #[derive(serde::Deserialize)] with // no customizations (e.g. renames)". @@ -125,7 +123,7 @@ pub(crate) fn verify_route_parameters( continue; } - let route_parameter_names = path + let path_parameter_names = path .split('/') .filter_map(|s| s.strip_prefix(':').or_else(|| s.strip_prefix('*'))) .collect::>(); @@ -151,21 +149,21 @@ pub(crate) fn verify_route_parameters( struct_field_names }; - let non_existing_route_parameters = struct_field_names + let non_existing_path_parameters = struct_field_names .into_iter() - .filter(|f| !route_parameter_names.contains(f.as_str())) + .filter(|f| !path_parameter_names.contains(f.as_str())) .collect::>(); - if !non_existing_route_parameters.is_empty() { - report_non_existing_route_parameters( + if !non_existing_path_parameters.is_empty() { + report_non_existing_path_parameters( component_db, package_graph, diagnostics, path, graph, - ok_route_params_node_id, - route_parameter_names, - non_existing_route_parameters, + ok_path_params_node_id, + path_parameter_names, + non_existing_path_parameters, extracted_type, ) } @@ -173,25 +171,24 @@ pub(crate) fn verify_route_parameters( } } -/// Report an error on each compute node that consumes the `RouteParams` extractor -/// while trying to extract one or more route parameters that are not present in -/// the respective route template. -fn report_non_existing_route_parameters( +/// Report an error on each compute node that consumes the `PathParams` extractor +/// while trying to extract one or more path parameters that are not present in +/// the respective path pattern. +fn report_non_existing_path_parameters( component_db: &ComponentDb, package_graph: &PackageGraph, diagnostics: &mut Vec, path: &str, call_graph: &RawCallGraph, - ok_route_params_node_id: NodeIndex, - route_parameter_names: IndexSet<&str>, - non_existing_route_parameters: IndexSet, + ok_path_params_node_id: NodeIndex, + path_parameter_names: IndexSet<&str>, + non_existing_path_parameters: IndexSet, extracted_type: &ResolvedType, ) { - assert!(!non_existing_route_parameters.is_empty()); - // Find the compute nodes that consume the `RouteParams` extractor and report + assert!(!non_existing_path_parameters.is_empty()); + // Find the compute nodes that consume the `PathParams` extractor and report // an error on each of them. - let consuming_ids = - route_params_consumer_ids(component_db, call_graph, ok_route_params_node_id); + let consuming_ids = path_params_consumer_ids(component_db, call_graph, ok_path_params_node_id); for user_component_id in consuming_ids { let raw_identifiers = component_db .user_component_db() @@ -208,34 +205,36 @@ fn report_non_existing_route_parameters( } }; let source_span = diagnostic::get_f_macro_invocation_span(&source, location); - if route_parameter_names.is_empty() { + if path_parameter_names.is_empty() { let error = anyhow!( - "`{}` is trying to extract route parameters using `RouteParams<{extracted_type:?}>`.\n\ - But there are no route parameters in `{path}`, the corresponding route template!", + "`{}` is trying to extract path parameters using `PathParams<{extracted_type:?}>`.\n\ + But there are no path parameters in `{path}`, the corresponding path pattern!", raw_identifiers.fully_qualified_path().join("::"), ); let d = CompilerDiagnostic::builder(source, error) .optional_label(source_span.labeled(format!( - "The {callable_type} asking for `RouteParams<{extracted_type:?}>`" + "The {callable_type} asking for `PathParams<{extracted_type:?}>`" ))) .help( - "Stop trying to extract route parameters, or add them to the route template!" + "Stop trying to extract path parameters, or add them to the path pattern!" .into(), ) .build(); diagnostics.push(d.into()); } else { - let missing_msg = if non_existing_route_parameters.len() == 1 { - let name = non_existing_route_parameters.first().unwrap(); + let missing_msg = if non_existing_path_parameters.len() == 1 { + let name = non_existing_path_parameters.first().unwrap(); format!( - "There is no route parameter named `{name}`, but there is a struct field named `{name}` \ + "There is no path parameter named `{name}`, but there is a struct field named `{name}` \ in `{extracted_type:?}`" ) } else { - let mut msg = "There are no route parameters named ".to_string(); + use std::fmt::Write; + + let mut msg = "There are no path parameters named ".to_string(); comma_separated_list( &mut msg, - non_existing_route_parameters.iter(), + non_existing_path_parameters.iter(), |p| format!("`{p}`"), "or", ) @@ -247,24 +246,23 @@ fn report_non_existing_route_parameters( .unwrap(); msg }; - let route_parameters = route_parameter_names + let path_parameters = path_parameter_names .iter() .map(|p| format!("- `{}`", p)) .join("\n"); let error = anyhow!( - "`{}` is trying to extract route parameters using `RouteParams<{extracted_type:?}>`.\n\ + "`{}` is trying to extract path parameters using `PathParams<{extracted_type:?}>`.\n\ Every struct field in `{extracted_type:?}` must be named after one of the route \ - parameters that appear in `{path}`:\n{route_parameters}\n\n\ + parameters that appear in `{path}`:\n{path_parameters}\n\n\ {missing_msg}. This is going to cause a runtime error!", raw_identifiers.fully_qualified_path().join("::"), ); let d = CompilerDiagnostic::builder(source, error) .optional_label(source_span.labeled(format!( - "The {callable_type} asking for `RouteParams<{extracted_type:?}>`" + "The {callable_type} asking for `PathParams<{extracted_type:?}>`" ))) .help( - "Remove or rename the fields that do not map to a valid route parameter." - .into(), + "Remove or rename the fields that do not map to a valid path parameter.".into(), ) .build(); diagnostics.push(d.into()); @@ -272,17 +270,17 @@ fn report_non_existing_route_parameters( } } -/// Checks that the type of the route parameter is a struct with named fields. +/// Checks that the type of the path parameter is a struct with named fields. /// If it is, returns the rustdoc item for the type. /// If it isn't, reports an error diagnostic on each compute node that consumes the -/// `RouteParams` extractor. +/// `PathParams` extractor. fn must_be_a_plain_struct( component_db: &ComponentDb, package_graph: &PackageGraph, krate_collection: &CrateCollection, diagnostics: &mut Vec, call_graph: &RawCallGraph, - ok_route_params_node_id: NodeIndex, + ok_path_params_node_id: NodeIndex, extracted_type: &ResolvedType, ) -> Result { let error_suffix = match extracted_type { @@ -316,10 +314,9 @@ fn must_be_a_plain_struct( } }; - // Find the compute nodes that consume the `RouteParams` extractor and report + // Find the compute nodes that consume the `PathParams` extractor and report // an error on each of them. - let consuming_ids = - route_params_consumer_ids(component_db, call_graph, ok_route_params_node_id); + let consuming_ids = path_params_consumer_ids(component_db, call_graph, ok_path_params_node_id); for user_component_id in consuming_ids { let raw_identifiers = component_db @@ -338,21 +335,21 @@ fn must_be_a_plain_struct( }; let source_span = diagnostic::get_f_macro_invocation_span(&source, location); let error = anyhow!( - "Route parameters must be extracted using a plain struct with named fields, \ - where the name of each field matches one of the route parameters specified \ + "Path parameters must be extracted using a plain struct with named fields, \ + where the name of each field matches one of the path parameters specified \ in the route for the respective request handler.\n\ - `{}` is trying to extract `RouteParams<{extracted_type:?}>`, but \ + `{}` is trying to extract `PathParams<{extracted_type:?}>`, but \ {error_suffix}, not a plain struct type. I don't support this: the extraction would \ fail at runtime, when trying to process an incoming request.", raw_identifiers.fully_qualified_path().join("::") ); let d = CompilerDiagnostic::builder(source, error) .optional_label(source_span.labeled(format!( - "The {callable_type} asking for `RouteParams<{extracted_type:?}>`" + "The {callable_type} asking for `PathParams<{extracted_type:?}>`" ))) .help( - "Use a plain struct with named fields to extract route parameters.\n\ - Check out `RouteParams`' documentation for all the details!" + "Use a plain struct with named fields to extract path parameters.\n\ + Check out `PathParams`' documentation for all the details!" .into(), ) .build(); @@ -361,16 +358,16 @@ fn must_be_a_plain_struct( Err(()) } -/// Return the set of user component ids that consume a certain instance of the `RouteParams` extractor +/// Return the set of user component ids that consume a certain instance of the `PathParams` extractor /// as input parameter. -fn route_params_consumer_ids( +fn path_params_consumer_ids( component_db: &ComponentDb, call_graph: &RawCallGraph, - ok_route_params_node_id: NodeIndex, + ok_path_params_node_id: NodeIndex, ) -> IndexSet { let mut consumer_ids = IndexSet::new(); let mut descendant_ids = call_graph - .neighbors_directed(ok_route_params_node_id, Direction::Outgoing) + .neighbors_directed(ok_path_params_node_id, Direction::Outgoing) .collect::>(); while let Some(descendant_id) = descendant_ids.pop() { let descendant_node = &call_graph[descendant_id]; diff --git a/mkdocs.yml b/mkdocs.yml index 1820e9b5d..a239c4d4b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -88,7 +88,7 @@ nav: - guide/request_data/request_target.md - "Path": - guide/request_data/path/index.md - - guide/request_data/path/route_parameters.md + - guide/request_data/path/path_parameters.md - "Query": - guide/request_data/query/index.md - guide/request_data/query/query_parameters.md diff --git a/template/template/{{crate_name}}/src/blueprint.rs b/template/template/{{crate_name}}/src/blueprint.rs index 1a0462cb8..534229f9e 100644 --- a/template/template/{{crate_name}}/src/blueprint.rs +++ b/template/template/{{crate_name}}/src/blueprint.rs @@ -1,6 +1,6 @@ use pavex::blueprint::constructor::CloningStrategy; use pavex::blueprint::{constructor::Lifecycle, router::GET, Blueprint}; -use pavex::request::{query::QueryParams, route::RouteParams}; +use pavex::request::{query::QueryParams, path::PathParams}; use pavex::request::body::{BodySizeLimit, BufferedBody, JsonBody}; use pavex::f; @@ -18,7 +18,7 @@ pub fn blueprint() -> Blueprint { /// Common constructors used by all routes. fn register_common_constructors(bp: &mut Blueprint) { - RouteParams::register(bp); + PathParams::register(bp); QueryParams::register(bp); JsonBody::register(bp); BufferedBody::register(bp); diff --git a/template/template/{{crate_name}}/src/telemetry.rs b/template/template/{{crate_name}}/src/telemetry.rs index 72dd680ce..bdcdcd99f 100644 --- a/template/template/{{crate_name}}/src/telemetry.rs +++ b/template/template/{{crate_name}}/src/telemetry.rs @@ -1,4 +1,4 @@ -use pavex::request::route::MatchedRouteTemplate; +use pavex::request::path::MatchedPathPattern; use pavex::http::Version; use pavex::middleware::Next; use pavex::request::RequestHead; @@ -37,7 +37,7 @@ impl RootSpan { /// /// We follow OpenTelemetry's HTTP semantic conventions as closely as /// possible for field naming. - pub fn new(request_head: &RequestHead, matched_route: MatchedRouteTemplate) -> Self { + pub fn new(request_head: &RequestHead, matched_route: MatchedPathPattern) -> Self { let user_agent = request_head .headers .get("User-Agent")