Skip to content

Commit

Permalink
Handle alloc correctly (#132)
Browse files Browse the repository at this point in the history
Fixes #131
  • Loading branch information
LukeMathWalker authored Dec 25, 2023
1 parent 1b4ca79 commit 295d7dd
Show file tree
Hide file tree
Showing 47 changed files with 185 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down Expand Up @@ -31,8 +30,8 @@ async fn route_request(
request: http::Request<hyper::body::Incoming>,
server_state: std::sync::Arc<ServerState>,
) -> pavex::response::Response {
#[allow(unused)]
let (request_head, request_body) = request.into_parts();
#[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()) {
Expand Down
3 changes: 1 addition & 2 deletions examples/realworld/api_server_sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
3 changes: 1 addition & 2 deletions examples/skeleton/app_server_sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 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;
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//! Do NOT edit this code.
//! It was automatically generated by Pavex.
//! All manual edits will be lost next time the code is generated.
extern crate alloc;
struct ServerState {
router: matchit::Router<u32>,
application_state: ApplicationState,
}
pub struct ApplicationState {
s0: alloc::sync::Arc<app::Custom>,
}
pub async fn build_application_state() -> crate::ApplicationState {
let v0 = app::constructor();
crate::ApplicationState { s0: v0 }
}
pub fn run(
server_builder: pavex::server::Server,
application_state: ApplicationState,
) -> pavex::server::ServerHandle {
let server_state = std::sync::Arc::new(ServerState {
router: build_router(),
application_state,
});
server_builder.serve(route_request, server_state)
}
fn build_router() -> matchit::Router<u32> {
let mut router = matchit::Router::new();
router.insert("/", 0u32).unwrap();
router
}
async fn route_request(
request: http::Request<hyper::body::Incoming>,
server_state: std::sync::Arc<ServerState>,
) -> pavex::response::Response {
let (request_head, request_body) = request.into_parts();
#[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()) {
Ok(m) => m,
Err(_) => {
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();
match route_id {
0u32 => {
match &request_head.method {
&pavex::http::Method::GET => {
route_0::handler(server_state.application_state.s0.clone()).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),
}
}
pub mod route_0 {
pub async fn handler(
v0: alloc::sync::Arc<app::Custom>,
) -> pavex::response::Response {
let v1 = app::handler(v0);
<http::StatusCode as pavex::response::IntoResponse>::into_response(v1)
}
}
pub mod route_1 {
pub async fn handler(
v0: &pavex::router::AllowedMethods,
) -> pavex::response::Response {
let v1 = pavex::router::default_fallback(v0).await;
<pavex::response::Response as pavex::response::IntoResponse>::into_response(v1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
digraph "GET / - 0" {
0 [ label = "app::handler(alloc::sync::Arc<app::Custom>) -> http::StatusCode"]
1 [ label = "alloc::sync::Arc<app::Custom>"]
2 [ label = "<http::StatusCode as pavex::response::IntoResponse>::into_response(http::StatusCode) -> pavex::response::Response"]
1 -> 0 [ ]
0 -> 2 [ ]
}

digraph "* / - 0" {
0 [ label = "pavex::router::default_fallback(&pavex::router::AllowedMethods) -> pavex::response::Response"]
2 [ label = "<pavex::response::Response as pavex::response::IntoResponse>::into_response(pavex::response::Response) -> pavex::response::Response"]
3 [ label = "&pavex::router::AllowedMethods"]
0 -> 2 [ ]
3 -> 0 [ ]
}

digraph app_state {
0 [ label = "crate::ApplicationState(alloc::sync::Arc<app::Custom>) -> crate::ApplicationState"]
1 [ label = "app::constructor() -> alloc::sync::Arc<app::Custom>"]
1 -> 0 [ ]
}
Loading

0 comments on commit 295d7dd

Please sign in to comment.