From ee5a31b9c5cc4b9181a982dfe0a6067004615f98 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 2 Aug 2020 23:11:56 +0800 Subject: [PATCH] style: code style --- Cargo.toml | 2 +- src/lib.rs | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index acdef75..9212e49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,5 @@ rust-crypto = "0.2.36" urlencoding = "1.0.0" base64 = "0.11.0" reqwest = "0.10.0" -rust_util="0.2.0" +rust_util="0.6.3" json = "0.12.0" diff --git a/src/lib.rs b/src/lib.rs index d15cbd3..ee7a37a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,22 +1,20 @@ +#[macro_use] +extern crate rust_util; + use std::{ io::Read, - fs::{ self, File, }, + fs::{ self, File }, env, path::PathBuf, - io::{ Error, ErrorKind, }, + io::{ Error, ErrorKind }, }; use crypto::{ - mac::{ Mac, MacResult, }, + mac::{ Mac, MacResult }, hmac::Hmac, sha1::Sha1, }; use reqwest::Response; -use rust_util::{ - iff, - XResult, - new_box_ioerror, - util_time::get_current_secs, -}; +use rust_util::{ XResult, new_box_ioerror, util_time::get_current_secs }; pub const OSS_VERB_GET: &str = "GET"; pub const OSS_VERB_PUT: &str = "PUT"; @@ -94,7 +92,7 @@ impl OSSClient { pub async fn put_file(&self, bucket_name: &str, key: &str, expire_in_seconds: u64, file: File) -> XResult { let put_url = self.generate_signed_put_url(bucket_name, key, expire_in_seconds); let client = reqwest::Client::new(); - let mut v = Vec::new(); + let mut v = vec![]; let mut file = file; file.read_to_end(&mut v)?; Ok(client.put(&put_url).body(v).send().await?) @@ -121,9 +119,7 @@ impl OSSClient { let response = reqwest::get(&get_url).await?; match response.status().as_u16() { 404_u16 => Ok(None), - 200_u16 => { - Ok(Some(response.bytes().await?.as_ref().to_vec())) - }, + 200_u16 => Ok(Some(response.bytes().await?.as_ref().to_vec())), _ => Err(new_box_ioerror(&format!("Error in read: {}/{}, returns: {:?}", bucket_name, key, response)) as Box), } }