From 099efb2da5f35bd5f6160c26f3587d2723f74050 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 18 Jun 2019 10:17:34 +0200 Subject: [PATCH] formatting fixup Signed-off-by: Wolfgang Bumiller --- proxmox-api/src/api_type.rs | 3 ++- proxmox-api/tests/cli.rs | 52 +++++++++++++++++++++++++++---------- proxmox-tools/src/lib.rs | 2 +- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/proxmox-api/src/api_type.rs b/proxmox-api/src/api_type.rs index 00eb003e..5c700994 100644 --- a/proxmox-api/src/api_type.rs +++ b/proxmox-api/src/api_type.rs @@ -197,7 +197,8 @@ impl ApiType for Option { DATA.once.call_once(|| { let info = T::type_info(); DATA.name.set(Some(format!("optional: {}", info.name))); - DATA.description.set(Some(format!("optional: {}", info.description))); + DATA.description + .set(Some(format!("optional: {}", info.description))); DATA.info.set(Some(TypeInfo { name: unsafe { (*DATA.name.as_ptr()).as_ref().unwrap().as_str() }, description: unsafe { (*DATA.description.as_ptr()).as_ref().unwrap().as_str() }, diff --git a/proxmox-api/tests/cli.rs b/proxmox-api/tests/cli.rs index 1e8761cb..b164cd76 100644 --- a/proxmox-api/tests/cli.rs +++ b/proxmox-api/tests/cli.rs @@ -19,7 +19,11 @@ fn simple() { check_cli(&cli, &["new", "--foo=FOO", "--bar=BAR"], Ok("FOO:BAR")); check_cli(&cli, &["new", "--foo", "FOO", "--bar=BAR"], Ok("FOO:BAR")); - check_cli(&cli, &["new", "--foo", "FOO", "--bar", "BAR"], Ok("FOO:BAR")); + check_cli( + &cli, + &["new", "--foo", "FOO", "--bar", "BAR"], + Ok("FOO:BAR"), + ); check_cli(&cli, &["new", "--foo=FOO"], Err("missing parameter: 'bar'")); check_cli(&cli, &["new", "--bar=BAR"], Err("missing parameter: 'foo'")); check_cli(&cli, &["new"], Err("missing parameter: 'foo'")); @@ -27,14 +31,26 @@ fn simple() { check_cli(&cli, &["newfoo", "POSFOO"], Err("missing parameter: 'bar'")); check_cli(&cli, &["newfoo", "POSFOO", "--bar=BAR"], Ok("POSFOO:BAR")); check_cli(&cli, &["newfoo", "--bar=BAR", "POSFOO"], Ok("POSFOO:BAR")); - check_cli(&cli, &["newfoo", "--bar=BAR"], Err("missing positional parameters: foo")); + check_cli( + &cli, + &["newfoo", "--bar=BAR"], + Err("missing positional parameters: foo"), + ); check_cli(&cli, &["newbar", "POSBAR"], Err("missing parameter: 'foo'")); check_cli(&cli, &["newbar", "POSBAR", "--foo=ABC"], Ok("ABC:POSBAR")); check_cli(&cli, &["newbar", "--foo=ABC", "POSBAR"], Ok("ABC:POSBAR")); - check_cli(&cli, &["newbar", "--foo=ABC"], Err("missing positional parameters: bar")); + check_cli( + &cli, + &["newbar", "--foo=ABC"], + Err("missing positional parameters: bar"), + ); - check_cli(&cli, &["newfoo", "FOO1", "--foo=FOO2", "--bar=BAR", "--baz=OMG"], Ok("FOO2:BAR:OMG")); + check_cli( + &cli, + &["newfoo", "FOO1", "--foo=FOO2", "--bar=BAR", "--baz=OMG"], + Ok("FOO2:BAR:OMG"), + ); } fn check_cli(cli: &cli::App, args: &[&str], expect: Result<&str, &str>) { @@ -48,15 +64,19 @@ fn check_cli(cli: &cli::App, args: &[&str], expect: Result<&str, &str>) { let result = result.to_string(); assert_eq!(result, expected, "expected specific error message"); } - (Ok(result), Err(err)) => { - match std::str::from_utf8(result.body().as_ref()) { - Ok(value) => panic!("expected error '{}', got success with value '{}'", err, value), - Err(_) => panic!("expected error '{}', got success with non-utf8 string", err), - } - } + (Ok(result), Err(err)) => match std::str::from_utf8(result.body().as_ref()) { + Ok(value) => panic!( + "expected error '{}', got success with value '{}'", + err, value + ), + Err(_) => panic!("expected error '{}', got success with non-utf8 string", err), + }, (Err(err), Ok(expected)) => { let err = err.to_string(); - panic!("expected success with value '{}', got error '{}'", expected, err); + panic!( + "expected success with value '{}', got error '{}'", + expected, err + ); } } } @@ -71,7 +91,9 @@ mod methods { use proxmox_api::{get_type_info, ApiFuture, ApiMethod, ApiOutput, ApiType, Parameter}; fn required_str<'a>(value: &'a Value, name: &'static str) -> Result<&'a str, Error> { - value[name].as_str().ok_or_else(|| format_err!("missing parameter: '{}'", name)) + value[name] + .as_str() + .ok_or_else(|| format_err!("missing parameter: '{}'", name)) } pub async fn simple_method(value: Value) -> ApiOutput { @@ -80,7 +102,11 @@ mod methods { let baz = value .get("baz") - .map(|value| value.as_str().ok_or_else(|| format_err!("'baz' must be a string"))) + .map(|value| { + value + .as_str() + .ok_or_else(|| format_err!("'baz' must be a string")) + }) .transpose()?; let output = match baz { diff --git a/proxmox-tools/src/lib.rs b/proxmox-tools/src/lib.rs index 830aa765..24ad5574 100644 --- a/proxmox-tools/src/lib.rs +++ b/proxmox-tools/src/lib.rs @@ -3,8 +3,8 @@ use failure::*; pub mod io; -pub mod vec; pub mod serde; +pub mod vec; /// Evaluates to the offset (in bytes) of a given member within a struct #[macro_export]