From 0a7a0deedb6b7c7b06991149d196819efb1057d5 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Fri, 27 Dec 2019 01:04:12 +0800 Subject: [PATCH] add iff! --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6c9290e..2e38e73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,13 @@ use reqwest::{ }; use rust_util::*; +/// iff!(condition, result_when_true, result_when_false) +macro_rules! iff { + ($c:expr, $t:expr, $f:expr) => { + if $c { $t } else { $f } + }; +} + pub const OSS_VERB_GET: &str = "GET"; pub const OSS_VERB_PUT: &str = "PUT"; pub const OSS_VERB_DELETE: &str = "DELETE"; @@ -83,7 +90,7 @@ impl<'a> OSSClient<'a> { pub fn generate_signed_url(&self, verb: &str, bucket_name: &str, key: &str, expire_in_seconds: u64, is_https: bool) -> String { let mut signed_url = String::with_capacity(1024); - signed_url.push_str(if is_https { "https://" } else { "http://" }); + signed_url.push_str(iff!(is_https, "https://", "http://")); signed_url.push_str(&format!("{}.{}/{}", bucket_name, self.endpoint, key)); let current_secs = get_current_secs();