From a5af6eedf719bc88c7fe37a7be2566655659fbbb Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 17 Jun 2019 12:32:22 +0200 Subject: [PATCH] formatting fixup Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api_def.rs | 4 ++- proxmox-api/src/cli.rs | 3 +- proxmox-tools/src/lib.rs | 50 ++++++++++++++++++++++---------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/proxmox-api-macro/src/api_def.rs b/proxmox-api-macro/src/api_def.rs index 78a258ed..9a76d2b3 100644 --- a/proxmox-api-macro/src/api_def.rs +++ b/proxmox-api-macro/src/api_def.rs @@ -46,7 +46,9 @@ impl CliMode { pub fn quote(&self, name: &proc_macro2::Ident) -> TokenStream { match self { CliMode::Disabled => quote! { None }, - CliMode::ParseCli => quote! { Some(<#name as ::proxmox::api::cli::ParseCli>::parse_cli) }, + CliMode::ParseCli => { + quote! { Some(<#name as ::proxmox::api::cli::ParseCli>::parse_cli) } + } CliMode::FromStr => quote! { Some(<#name as ::proxmox::api::cli::ParseCliFromStr>::parse_cli) }, diff --git a/proxmox-api/src/cli.rs b/proxmox-api/src/cli.rs index 2bdaaed2..7bed0e20 100644 --- a/proxmox-api/src/cli.rs +++ b/proxmox-api/src/cli.rs @@ -304,7 +304,8 @@ impl ParseCliFromStr for T where T: FromStr + Serialize, ::Err: Into, -{} +{ +} #[macro_export] macro_rules! no_cli_type { diff --git a/proxmox-tools/src/lib.rs b/proxmox-tools/src/lib.rs index f9947ccc..0d6695bf 100644 --- a/proxmox-tools/src/lib.rs +++ b/proxmox-tools/src/lib.rs @@ -10,7 +10,7 @@ pub mod vec; macro_rules! offsetof { ($ty:ty, $field:ident) => { unsafe { &(*(0 as *const $ty)).$field as *const _ as usize } - } + }; } const HEX_CHARS: &'static [u8; 16] = b"0123456789abcdef"; @@ -20,7 +20,7 @@ pub fn digest_to_hex(digest: &[u8]) -> String { } pub fn bin_to_hex(digest: &[u8]) -> String { - let mut buf = Vec::::with_capacity(digest.len()*2); + let mut buf = Vec::::with_capacity(digest.len() * 2); for i in 0..digest.len() { buf.push(HEX_CHARS[(digest[i] >> 4) as usize]); @@ -35,19 +35,27 @@ pub fn hex_to_bin(hex: &str) -> Result, Error> { let bytes = hex.as_bytes(); - if (bytes.len() % 2) != 0 { bail!("hex_to_bin: got wrong input length."); } + if (bytes.len() % 2) != 0 { + bail!("hex_to_bin: got wrong input length."); + } let val = |c| { - if c >= b'0' && c <= b'9' { return Ok(c - b'0'); } - if c >= b'a' && c <= b'f' { return Ok(c - b'a' + 10); } - if c >= b'A' && c <= b'F' { return Ok(c - b'A' + 10); } + if c >= b'0' && c <= b'9' { + return Ok(c - b'0'); + } + if c >= b'a' && c <= b'f' { + return Ok(c - b'a' + 10); + } + if c >= b'A' && c <= b'F' { + return Ok(c - b'A' + 10); + } bail!("found illegal hex character."); }; for pair in bytes.chunks(2) { let h = val(pair[0])?; let l = val(pair[1])?; - result.push((h<<4)|l); + result.push((h << 4) | l); } Ok(result) @@ -58,25 +66,37 @@ pub fn hex_to_digest(hex: &str) -> Result<[u8; 32], Error> { let bytes = hex.as_bytes(); - if bytes.len() != 64 { bail!("got wrong digest length."); } + if bytes.len() != 64 { + bail!("got wrong digest length."); + } let val = |c| { - if c >= b'0' && c <= b'9' { return Ok(c - b'0'); } - if c >= b'a' && c <= b'f' { return Ok(c - b'a' + 10); } - if c >= b'A' && c <= b'F' { return Ok(c - b'A' + 10); } + if c >= b'0' && c <= b'9' { + return Ok(c - b'0'); + } + if c >= b'a' && c <= b'f' { + return Ok(c - b'a' + 10); + } + if c >= b'A' && c <= b'F' { + return Ok(c - b'A' + 10); + } bail!("found illegal hex character."); }; let mut pos = 0; for pair in bytes.chunks(2) { - if pos >= digest.len() { bail!("hex digest too long."); } + if pos >= digest.len() { + bail!("hex digest too long."); + } let h = val(pair[0])?; let l = val(pair[1])?; - digest[pos] = (h<<4)|l; - pos +=1; + digest[pos] = (h << 4) | l; + pos += 1; } - if pos != digest.len() { bail!("hex digest too short."); } + if pos != digest.len() { + bail!("hex digest too short."); + } Ok(digest) }