formatting fixup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-06-07 12:03:13 +02:00
parent b5c05fc85c
commit 3dd6cd3fe0
7 changed files with 36 additions and 26 deletions

View File

@ -51,11 +51,13 @@ fn handle_function(
// variables. (I'd prefer a struct and using `#{func.description}`, `#{func.protected}` etc. // variables. (I'd prefer a struct and using `#{func.description}`, `#{func.protected}` etc.
// but that's not supported. // but that's not supported.
let fn_api_description = definition.remove("description") let fn_api_description = definition
.remove("description")
.ok_or_else(|| format_err!("missing 'description' in method definition"))? .ok_or_else(|| format_err!("missing 'description' in method definition"))?
.expect_lit_str()?; .expect_lit_str()?;
let fn_api_protected = definition.remove("protected") let fn_api_protected = definition
.remove("protected")
.map(|v| v.expect_lit_bool()) .map(|v| v.expect_lit_bool())
.transpose()? .transpose()?
.unwrap_or_else(|| syn::LitBool { .unwrap_or_else(|| syn::LitBool {
@ -63,7 +65,8 @@ fn handle_function(
value: false, value: false,
}); });
let fn_api_reload_timezone = definition.remove("reload_timezone") let fn_api_reload_timezone = definition
.remove("reload_timezone")
.map(|v| v.expect_lit_bool()) .map(|v| v.expect_lit_bool())
.transpose()? .transpose()?
.unwrap_or_else(|| syn::LitBool { .unwrap_or_else(|| syn::LitBool {
@ -79,7 +82,9 @@ fn handle_function(
let name = std::mem::replace(&mut item.ident, impl_ident.clone()); let name = std::mem::replace(&mut item.ident, impl_ident.clone());
let mut return_type = match item.decl.output { let mut return_type = match item.decl.output {
syn::ReturnType::Default => syn::Type::Tuple(syn::TypeTuple { syn::ReturnType::Default => syn::Type::Tuple(syn::TypeTuple {
paren_token: syn::token::Paren { span: Span::call_site() }, paren_token: syn::token::Paren {
span: Span::call_site(),
},
elems: syn::punctuated::Punctuated::new(), elems: syn::punctuated::Punctuated::new(),
}), }),
syn::ReturnType::Type(_, ref ty) => ty.as_ref().clone(), syn::ReturnType::Type(_, ref ty) => ty.as_ref().clone(),
@ -215,11 +220,14 @@ fn handle_function(
} else { } else {
// Non async fn must return an ApiFuture already! // Non async fn must return an ApiFuture already!
return_type = syn::Type::Verbatim(syn::TypeVerbatim { return_type = syn::Type::Verbatim(syn::TypeVerbatim {
tts: definition.remove("returns") tts: definition
.ok_or_else(|| format_err!( .remove("returns")
"non async-fn must return a Response \ .ok_or_else(|| {
and specify its return type via the `returns` property", format_err!(
))? "non async-fn must return a Response \
and specify its return type via the `returns` property",
)
})?
.expect_ident()? .expect_ident()?
.into_token_stream(), .into_token_stream(),
}); });

View File

@ -70,7 +70,9 @@ async fn get_loopback(param: String) -> Result<String, Error> {
returns: String returns: String
})] })]
fn non_async_test(param: String) -> proxmox_api::ApiFuture { fn non_async_test(param: String) -> proxmox_api::ApiFuture {
Box::pin((async move || proxmox_api::IntoApiOutput::into_api_output(param))()) Box::pin((async move || {
proxmox_api::IntoApiOutput::into_api_output(param)
})())
} }
proxmox_api_macro::router! { proxmox_api_macro::router! {
@ -132,5 +134,8 @@ fn router() {
// And can I... // And can I...
let res = futures::executor::block_on(get_loopback("FOO".to_string())) let res = futures::executor::block_on(get_loopback("FOO".to_string()))
.expect("expected result from get_loopback"); .expect("expected result from get_loopback");
assert!(res == "FOO", "expected FOO from direct get_loopback('FOO') call"); assert!(
res == "FOO",
"expected FOO from direct get_loopback('FOO') call"
);
} }

View File

@ -1,4 +1,4 @@
//! Module to help converting various types into an ApiOutput, mostly required to support //! Module to help converting various types into an ApiOutput, mostly required to support
use serde_json::json; use serde_json::json;
@ -24,8 +24,7 @@ impl<T: ApiType + serde::Serialize> IntoApiOutput<()> for T {
Ok(http::Response::builder() Ok(http::Response::builder()
.status(200) .status(200)
.header("content-type", "application/json") .header("content-type", "application/json")
.body(bytes::Bytes::from(output))? .body(bytes::Bytes::from(output))?)
)
} }
} }

View File

@ -55,7 +55,9 @@ mod methods {
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use proxmox_api::{get_type_info, ApiFuture, ApiMethod, ApiOutput, ApiType, Parameter, TypeInfo}; use proxmox_api::{
get_type_info, ApiFuture, ApiMethod, ApiOutput, ApiType, Parameter, TypeInfo,
};
pub async fn get_people(value: Value) -> ApiOutput { pub async fn get_people(value: Value) -> ApiOutput {
Ok(Response::builder() Ok(Response::builder()
@ -79,9 +81,7 @@ mod methods {
return_type: get_type_info::<String>(), return_type: get_type_info::<String>(),
protected: false, protected: false,
reload_timezone: false, reload_timezone: false,
handler: |value: Value| -> ApiFuture { handler: |value: Value| -> ApiFuture { Box::pin(get_people(value)) },
Box::pin(get_people(value))
},
} }
}; };
} }

View File

@ -213,14 +213,10 @@ impl<R: io::Read> ReadExtOps for R {
} }
unsafe fn read_le_value<T: Endian>(&mut self) -> io::Result<T> { unsafe fn read_le_value<T: Endian>(&mut self) -> io::Result<T> {
Ok(self.read_host_value::<T>()?. Ok(self.read_host_value::<T>()?.from_le())
from_le()
)
} }
unsafe fn read_be_value<T: Endian>(&mut self) -> io::Result<T> { unsafe fn read_be_value<T: Endian>(&mut self) -> io::Result<T> {
Ok(self.read_host_value::<T>()? Ok(self.read_host_value::<T>()?.from_be())
.from_be()
)
} }
} }

View File

@ -1,4 +1,4 @@
//! This is a general utility crate used by all our rust projects. //! This is a general utility crate used by all our rust projects.
pub mod vec;
pub mod io; pub mod io;
pub mod vec;

View File

@ -106,7 +106,9 @@ mod vg {
MAKE_MEM_UNDEFINED, MAKE_MEM_UNDEFINED,
addr as usize as ValgrindValue, addr as usize as ValgrindValue,
len as ValgrindValue, len as ValgrindValue,
0, 0, 0, 0,
0,
0,
], ],
) )
} }