diff --git a/api-test/src/main.rs b/api-test/src/main.rs index d947582f..f75a6586 100644 --- a/api-test/src/main.rs +++ b/api-test/src/main.rs @@ -26,13 +26,12 @@ async fn route_request(request: Request) -> Result, E .lookup(path) .ok_or_else(|| format_err!("missing path: {}", path))?; - let handler = target + target .get .as_ref() .ok_or_else(|| format_err!("no GET method for: {}", path))? - .handler(); - - Ok(handler(params.unwrap_or(Value::Null)).await?) + .call(params.unwrap_or(Value::Null)) + .await } type BoxFut = Box, Error = hyper::Error> + Send>; diff --git a/proxmox-api-macro/src/api_macro.rs b/proxmox-api-macro/src/api_macro.rs index 3c05bfd1..0da4e87a 100644 --- a/proxmox-api-macro/src/api_macro.rs +++ b/proxmox-api-macro/src/api_macro.rs @@ -357,8 +357,8 @@ fn handle_function( #fn_api_reload_timezone } - fn handler(&self) -> fn(::serde_json::Value) -> ::proxmox::api::ApiFuture<#body_type> { - #struct_name::wrapped_api_handler + fn call(&self, params: ::serde_json::Value) -> ::proxmox::api::ApiFuture<#body_type> { + #struct_name::wrapped_api_handler(params) } } }); diff --git a/proxmox-api-macro/tests/basic.rs b/proxmox-api-macro/tests/basic.rs index 29fa3f4f..43ad27c5 100644 --- a/proxmox-api-macro/tests/basic.rs +++ b/proxmox-api-macro/tests/basic.rs @@ -111,7 +111,7 @@ fn check_body(router: &Router, path: &str, expect: &'static str) { .get .as_ref() .expect("expected GET method on router at path"); - let fut = method.handler()(parameters.unwrap_or(Value::Null)); + let fut = method.call(parameters.unwrap_or(Value::Null)); let resp = futures::executor::block_on(fut) .expect("expected `GET` on test_body to return successfully"); assert!(resp.status() == 200, "test response should have status 200"); diff --git a/proxmox-api-macro/tests/verification.rs b/proxmox-api-macro/tests/verification.rs index a7648e72..7850dc3f 100644 --- a/proxmox-api-macro/tests/verification.rs +++ b/proxmox-api-macro/tests/verification.rs @@ -45,7 +45,7 @@ fn check_parameter( .get .as_ref() .expect("expected GET method on router at path"); - let fut = method.handler()(parameters); + let fut = method.call(parameters); match (futures::executor::block_on(fut), expect) { (Ok(resp), Ok(exp)) => { assert_eq!(resp.status(), 200, "test response should have status 200"); diff --git a/proxmox-api/src/api_type.rs b/proxmox-api/src/api_type.rs index 63a450f8..7d9063bd 100644 --- a/proxmox-api/src/api_type.rs +++ b/proxmox-api/src/api_type.rs @@ -15,7 +15,7 @@ pub trait ApiMethodInfo { fn return_type(&self) -> &'static TypeInfo; fn protected(&self) -> bool; fn reload_timezone(&self) -> bool; - fn handler(&self) -> fn(Value) -> super::ApiFuture; + fn call(&self, params: Value) -> super::ApiFuture; } /// Shortcut to not having to type it out. This function signature is just a dummy and not yet @@ -109,8 +109,8 @@ impl ApiMethodInfo for ApiMethod { self.reload_timezone } - fn handler(&self) -> fn(Value) -> super::ApiFuture { - self.handler + fn call(&self, params: Value) -> super::ApiFuture { + (self.handler)(params) } } diff --git a/proxmox-api/src/cli.rs b/proxmox-api/src/cli.rs index 4f12a52c..e9491ac4 100644 --- a/proxmox-api/src/cli.rs +++ b/proxmox-api/src/cli.rs @@ -165,14 +165,8 @@ where } fn call(&self, params: Value) -> super::ApiFuture { - //async fn real_handler(this: &Self, params: Value) -> ApiOutput { - // (Self::handler(this))(params) - // .await - // .map(|res| res.into()) - //} - let handler = self.handler(); use futures::future::TryFutureExt; - Box::pin(handler(params).map_ok(|res| res.map(|body| body.into()))) + Box::pin(ApiMethodInfo::call(self, params).map_ok(|res| res.map(|body| body.into()))) } } diff --git a/proxmox-api/tests/router.rs b/proxmox-api/tests/router.rs index 555d01c7..aacfbc5b 100644 --- a/proxmox-api/tests/router.rs +++ b/proxmox-api/tests/router.rs @@ -1,7 +1,5 @@ #![feature(async_await)] -use std::pin::Pin; - use bytes::Bytes; use proxmox_api::Router; @@ -52,12 +50,6 @@ fn check_with_matched_params( param_name, )); - let apifn = target - .get - .as_ref() - .expect(&format!("expected GET method on {}", path)) - .handler(); - let arg = params[param_name].as_str().expect(&format!( "expected lookup() to fill the '{}' parameter", param_name @@ -69,7 +61,13 @@ fn check_with_matched_params( path, param_name, param_value, ); - let response = futures::executor::block_on(Pin::from(apifn(params))) + let apifut = target + .get + .as_ref() + .expect(&format!("expected GET method on {}", path)) + .call(params); + + let response = futures::executor::block_on(apifut) .expect("expected the simple test api function to be ready immediately"); assert_eq!(response.status(), 200, "response status must be 200");