Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug related to generic arguments defined in a foreign crate wrt t…
…he typedef definition.
- Loading branch information
1 parent
9518d66
commit a950e54
Showing
6 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...ts/ui_tests/reflection/generic_parameters_can_come_from_another_crate/expectations/app.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
//! Do NOT edit this code. | ||
//! It was automatically generated by Pavex. | ||
//! All manual edits will be lost next time the code is generated. | ||
#[allow(unused_imports)] | ||
use std as alloc; | ||
struct ServerState { | ||
router: pavex_runtime::routing::Router<u32>, | ||
#[allow(dead_code)] | ||
application_state: ApplicationState, | ||
} | ||
pub struct ApplicationState {} | ||
pub async fn build_application_state() -> crate::ApplicationState { | ||
crate::ApplicationState {} | ||
} | ||
pub async fn run( | ||
server_builder: pavex_runtime::hyper::server::Builder< | ||
pavex_runtime::hyper::server::conn::AddrIncoming, | ||
>, | ||
application_state: ApplicationState, | ||
) -> Result<(), pavex_runtime::Error> { | ||
let server_state = std::sync::Arc::new(ServerState { | ||
router: build_router().map_err(pavex_runtime::Error::new)?, | ||
application_state, | ||
}); | ||
let make_service = pavex_runtime::hyper::service::make_service_fn(move |_| { | ||
let server_state = server_state.clone(); | ||
async move { | ||
Ok::< | ||
_, | ||
pavex_runtime::hyper::Error, | ||
>( | ||
pavex_runtime::hyper::service::service_fn(move |request| { | ||
let server_state = server_state.clone(); | ||
async move { | ||
Ok::< | ||
_, | ||
pavex_runtime::hyper::Error, | ||
>(route_request(request, server_state).await) | ||
} | ||
}), | ||
) | ||
} | ||
}); | ||
server_builder.serve(make_service).await.map_err(pavex_runtime::Error::new) | ||
} | ||
fn build_router() -> Result< | ||
pavex_runtime::routing::Router<u32>, | ||
pavex_runtime::routing::InsertError, | ||
> { | ||
let mut router = pavex_runtime::routing::Router::new(); | ||
router.insert("/home", 0u32)?; | ||
Ok(router) | ||
} | ||
async fn route_request( | ||
request: http::Request<pavex_runtime::hyper::body::Body>, | ||
server_state: std::sync::Arc<ServerState>, | ||
) -> pavex_runtime::response::Response { | ||
#[allow(unused)] | ||
let (request_head, request_body) = request.into_parts(); | ||
let request_head: pavex_runtime::request::RequestHead = request_head.into(); | ||
let matched_route = match server_state.router.at(&request_head.uri.path()) { | ||
Ok(m) => m, | ||
Err(_) => { | ||
return pavex_runtime::response::Response::builder() | ||
.status(pavex_runtime::http::StatusCode::NOT_FOUND) | ||
.body(pavex_runtime::body::boxed(hyper::body::Body::empty())) | ||
.unwrap(); | ||
} | ||
}; | ||
let route_id = matched_route.value; | ||
#[allow(unused)] | ||
let url_params: pavex_runtime::extract::route::RawRouteParams<'_, '_> = matched_route | ||
.params | ||
.into(); | ||
match route_id { | ||
0u32 => { | ||
match &request_head.method { | ||
&pavex_runtime::http::Method::GET => route_handler_0().await, | ||
_ => { | ||
pavex_runtime::response::Response::builder() | ||
.status(pavex_runtime::http::StatusCode::METHOD_NOT_ALLOWED) | ||
.header(pavex_runtime::http::header::ALLOW, "GET") | ||
.body(pavex_runtime::body::boxed(hyper::body::Body::empty())) | ||
.unwrap() | ||
} | ||
} | ||
} | ||
_ => { | ||
pavex_runtime::response::Response::builder() | ||
.status(pavex_runtime::http::StatusCode::NOT_FOUND) | ||
.body(pavex_runtime::body::boxed(hyper::body::Body::empty())) | ||
.unwrap() | ||
} | ||
} | ||
} | ||
pub async fn route_handler_0() -> http::Response< | ||
http_body::combinators::BoxBody<bytes::Bytes, pavex_runtime::Error>, | ||
> { | ||
let v0 = app::handler(); | ||
<http::Response< | ||
app::BodyType, | ||
> as pavex_runtime::response::IntoResponse>::into_response(v0) | ||
} |
8 changes: 8 additions & 0 deletions
8
...ts/reflection/generic_parameters_can_come_from_another_crate/expectations/diagnostics.dot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
digraph "GET /home" { | ||
0 [ label = "app::handler() -> http::Response<app::BodyType>"] | ||
1 [ label = "<http::Response::<app::BodyType> as pavex_runtime::response::IntoResponse>::into_response(http::Response<app::BodyType>) -> http::Response<http_body::combinators::BoxBody<bytes::Bytes, pavex_runtime::Error>>"] | ||
0 -> 1 [ ] | ||
} | ||
digraph app_state { | ||
0 [ label = "crate::ApplicationState() -> crate::ApplicationState"] | ||
} |
40 changes: 40 additions & 0 deletions
40
...pavex_cli/tests/ui_tests/reflection/generic_parameters_can_come_from_another_crate/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use pavex_builder::{f, router::GET, Blueprint}; | ||
use pavex_runtime::response::IntoResponse; | ||
use pavex_runtime::response::Response; | ||
|
||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/home", f!(crate::handler)); | ||
bp | ||
} | ||
|
||
// A locally-definited type | ||
pub struct BodyType { | ||
pub name: String, | ||
pub age: u8, | ||
} | ||
|
||
impl http_body::Body for BodyType { | ||
type Data = bytes::Bytes; | ||
type Error = pavex_runtime::Error; | ||
|
||
fn poll_data( | ||
self: std::pin::Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<Option<Result<Self::Data, Self::Error>>> { | ||
todo!() | ||
} | ||
|
||
fn poll_trailers( | ||
self: std::pin::Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<Result<Option<pavex_runtime::http::HeaderMap>, Self::Error>> { | ||
todo!() | ||
} | ||
} | ||
|
||
// The `Response` type comes from `pavex_runtime` but the body | ||
// type is defined in this crate. | ||
pub fn handler() -> Response<BodyType> { | ||
todo!() | ||
} |
11 changes: 11 additions & 0 deletions
11
...tests/ui_tests/reflection/generic_parameters_can_come_from_another_crate/test_config.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
description = """ | ||
Pavex handles types whose generic parameter are not defined in the same crate | ||
that defines the base type | ||
""" | ||
|
||
[expectations] | ||
codegen = "pass" | ||
|
||
[dependencies] | ||
http-body = "0.4" | ||
bytes = "1" |
2 changes: 1 addition & 1 deletion
2
libs/pavex_cli/tests/ui_tests/reflection/local_glob_reexports_are_supported/test_config.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters