From a4abaa8b174772f8ffc4a8c5f4fc0662b0e7f0b8 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 16 Jul 2020 14:13:13 +0200 Subject: [PATCH] api-macro: formatting fixups Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api.rs | 5 ++- proxmox-api-macro/src/api/method.rs | 2 +- proxmox-api-macro/src/api/structs.rs | 23 +++++------ proxmox-api-macro/tests/int-limits.rs | 3 +- proxmox-api-macro/tests/options.rs | 10 +++-- proxmox-api-macro/tests/types.rs | 58 +++++++++++++-------------- 6 files changed, 48 insertions(+), 53 deletions(-) diff --git a/proxmox-api-macro/src/api.rs b/proxmox-api-macro/src/api.rs index 165dbf00..2d2dada1 100644 --- a/proxmox-api-macro/src/api.rs +++ b/proxmox-api-macro/src/api.rs @@ -193,7 +193,7 @@ impl Schema { fn find_schema_property(&self, key: &str) -> Option<&syn::Expr> { for prop in &self.properties { if prop.0 == key { - return Some(&prop.1) + return Some(&prop.1); } } None @@ -201,7 +201,8 @@ impl Schema { pub fn add_default_property(&mut self, key: &str, value: syn::Expr) { if self.find_schema_property(key).is_none() { - self.properties.push((Ident::new(key, Span::call_site()), value)); + self.properties + .push((Ident::new(key, Span::call_site()), value)); } } } diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index da786533..e94594f2 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -45,7 +45,7 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result quote_spanned! { desc.span() => Some(#desc) }, - None => quote_spanned! { access.span => None } + None => quote_spanned! { access.span => None }, }; quote_spanned! { access.span => .access(#description, #permission) diff --git a/proxmox-api-macro/src/api/structs.rs b/proxmox-api-macro/src/api/structs.rs index 0c581162..72843a1f 100644 --- a/proxmox-api-macro/src/api/structs.rs +++ b/proxmox-api-macro/src/api/structs.rs @@ -34,7 +34,7 @@ pub fn handle_struct(attribs: JSONObject, stru: syn::ItemStruct) -> Result handle_regular_struct(attribs, stru) + syn::Fields::Named(_) => handle_regular_struct(attribs, stru), } } @@ -47,10 +47,7 @@ fn get_struct_description(schema: &mut Schema, stru: &syn::ItemStruct) -> Result Ok(()) } -fn handle_unit_struct( - attribs: JSONObject, - stru: syn::ItemStruct, -) -> Result { +fn handle_unit_struct(attribs: JSONObject, stru: syn::ItemStruct) -> Result { // unit structs, not sure about these? let mut schema: Schema = if attribs.is_empty() { @@ -83,10 +80,7 @@ fn finish_schema( }) } -fn handle_newtype_struct( - attribs: JSONObject, - stru: syn::ItemStruct, -) -> Result { +fn handle_newtype_struct(attribs: JSONObject, stru: syn::ItemStruct) -> Result { // Ideally we could clone the contained item's schema, but this is "hard", so for now we assume // the contained type is a simple type. // @@ -104,7 +98,11 @@ fn handle_newtype_struct( _ => panic!("handle_unit_struct on non-unit struct"), }; // this is also part of `handle_struct()`'s verification! - assert_eq!(fields.len(), 1, "handle_unit_struct needs a struct with exactly 1 field"); + assert_eq!( + fields.len(), + 1, + "handle_unit_struct needs a struct with exactly 1 field" + ); // Now infer the type information: util::infer_type(&mut schema, &fields[0].ty)?; @@ -115,10 +113,7 @@ fn handle_newtype_struct( finish_schema(schema, &stru, &stru.ident) } -fn handle_regular_struct( - attribs: JSONObject, - stru: syn::ItemStruct, -) -> Result { +fn handle_regular_struct(attribs: JSONObject, stru: syn::ItemStruct) -> Result { let mut schema: Schema = if attribs.is_empty() { Schema::empty_object(Span::call_site()) } else { diff --git a/proxmox-api-macro/tests/int-limits.rs b/proxmox-api-macro/tests/int-limits.rs index 70f19108..7606a14c 100644 --- a/proxmox-api-macro/tests/int-limits.rs +++ b/proxmox-api-macro/tests/int-limits.rs @@ -69,8 +69,7 @@ pub struct AnI64(i64); #[test] fn test_an_i64_schema() { const TEST_SCHEMA: ::proxmox::api::schema::Schema = - ::proxmox::api::schema::IntegerSchema::new("An i64: this is left unlimited.") - .schema(); + ::proxmox::api::schema::IntegerSchema::new("An i64: this is left unlimited.").schema(); assert_eq!(TEST_SCHEMA, AnI64::API_SCHEMA); } diff --git a/proxmox-api-macro/tests/options.rs b/proxmox-api-macro/tests/options.rs index 58ce39d1..d59e0ad4 100644 --- a/proxmox-api-macro/tests/options.rs +++ b/proxmox-api-macro/tests/options.rs @@ -77,11 +77,13 @@ fn test_invocations() { .expect("func with option should work"); assert_eq!(value, true); - let value = api_function_test_option(json!({"value": false}), &API_METHOD_TEST_OPTION, &mut env) - .expect("func with option should work"); + let value = + api_function_test_option(json!({"value": false}), &API_METHOD_TEST_OPTION, &mut env) + .expect("func with option should work"); assert_eq!(value, false); - let value = api_function_test_default_macro(json!({}), &API_METHOD_TEST_DEFAULT_MACRO, &mut env) - .expect("func with option should work"); + let value = + api_function_test_default_macro(json!({}), &API_METHOD_TEST_DEFAULT_MACRO, &mut env) + .expect("func with option should work"); assert_eq!(value, 5); } diff --git a/proxmox-api-macro/tests/types.rs b/proxmox-api-macro/tests/types.rs index a85971d6..e121c3fd 100644 --- a/proxmox-api-macro/tests/types.rs +++ b/proxmox-api-macro/tests/types.rs @@ -84,26 +84,25 @@ pub struct RenamedStruct { #[test] fn renamed_struct() { - const TEST_SCHEMA: ::proxmox::api::schema::Schema = - ::proxmox::api::schema::ObjectSchema::new( - "An example of a struct with renamed fields.", - &[ - ( - "SomeOther", - true, - &::proxmox::api::schema::StringSchema::new( - "An optional auto-derived value for testing:", - ) - .schema(), - ), - ( - "test-string", - false, - &::proxmox::api::schema::StringSchema::new("A test string.").schema(), - ), - ], - ) - .schema(); + const TEST_SCHEMA: ::proxmox::api::schema::Schema = ::proxmox::api::schema::ObjectSchema::new( + "An example of a struct with renamed fields.", + &[ + ( + "SomeOther", + true, + &::proxmox::api::schema::StringSchema::new( + "An optional auto-derived value for testing:", + ) + .schema(), + ), + ( + "test-string", + false, + &::proxmox::api::schema::StringSchema::new("A test string.").schema(), + ), + ], + ) + .schema(); assert_eq!(TEST_SCHEMA, RenamedStruct::API_SCHEMA); } @@ -124,16 +123,15 @@ pub enum Selection { #[test] fn selection_test() { - const TEST_SCHEMA: ::proxmox::api::schema::Schema = - ::proxmox::api::schema::StringSchema::new( - "A selection of either \'onekind\', \'another-kind\' or \'selection-number-three\'.", - ) - .format(&::proxmox::api::schema::ApiStringFormat::Enum(&[ - EnumEntry::new("onekind", "The first kind."), - EnumEntry::new("another-kind", "Some other kind."), - EnumEntry::new("selection-number-three", "And yet another."), - ])) - .schema(); + const TEST_SCHEMA: ::proxmox::api::schema::Schema = ::proxmox::api::schema::StringSchema::new( + "A selection of either \'onekind\', \'another-kind\' or \'selection-number-three\'.", + ) + .format(&::proxmox::api::schema::ApiStringFormat::Enum(&[ + EnumEntry::new("onekind", "The first kind."), + EnumEntry::new("another-kind", "Some other kind."), + EnumEntry::new("selection-number-three", "And yet another."), + ])) + .schema(); assert_eq!(TEST_SCHEMA, Selection::API_SCHEMA); }