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.
// 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"))?
.expect_lit_str()?;
let fn_api_protected = definition.remove("protected")
let fn_api_protected = definition
.remove("protected")
.map(|v| v.expect_lit_bool())
.transpose()?
.unwrap_or_else(|| syn::LitBool {
@ -63,7 +65,8 @@ fn handle_function(
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())
.transpose()?
.unwrap_or_else(|| syn::LitBool {
@ -79,7 +82,9 @@ fn handle_function(
let name = std::mem::replace(&mut item.ident, impl_ident.clone());
let mut return_type = match item.decl.output {
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(),
}),
syn::ReturnType::Type(_, ref ty) => ty.as_ref().clone(),
@ -215,11 +220,14 @@ fn handle_function(
} else {
// Non async fn must return an ApiFuture already!
return_type = syn::Type::Verbatim(syn::TypeVerbatim {
tts: definition.remove("returns")
.ok_or_else(|| format_err!(
"non async-fn must return a Response \
and specify its return type via the `returns` property",
))?
tts: definition
.remove("returns")
.ok_or_else(|| {
format_err!(
"non async-fn must return a Response \
and specify its return type via the `returns` property",
)
})?
.expect_ident()?
.into_token_stream(),
});

View File

@ -70,7 +70,9 @@ async fn get_loopback(param: String) -> Result<String, Error> {
returns: String
})]
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! {
@ -132,5 +134,8 @@ fn router() {
// And can I...
let res = futures::executor::block_on(get_loopback("FOO".to_string()))
.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;
@ -24,8 +24,7 @@ impl<T: ApiType + serde::Serialize> IntoApiOutput<()> for T {
Ok(http::Response::builder()
.status(200)
.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_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 {
Ok(Response::builder()
@ -79,9 +81,7 @@ mod methods {
return_type: get_type_info::<String>(),
protected: false,
reload_timezone: false,
handler: |value: Value| -> ApiFuture {
Box::pin(get_people(value))
},
handler: |value: Value| -> ApiFuture { 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> {
Ok(self.read_host_value::<T>()?.
from_le()
)
Ok(self.read_host_value::<T>()?.from_le())
}
unsafe fn read_be_value<T: Endian>(&mut self) -> io::Result<T> {
Ok(self.read_host_value::<T>()?
.from_be()
)
Ok(self.read_host_value::<T>()?.from_be())
}
}

View File

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

View File

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