From 926d557ab0c5bfb70e96b68351d134b591ee4c51 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 4 Apr 2020 22:39:29 +0800 Subject: [PATCH] update min/max --- src/config_util.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/config_util.rs b/src/config_util.rs index 73d35a7..921b91a 100644 --- a/src/config_util.rs +++ b/src/config_util.rs @@ -1,4 +1,5 @@ use std::{ + cmp::{min, max, }, fs, path::Path, }; @@ -98,13 +99,10 @@ impl OSSBackupdConfigItem { } pub fn get_safe_backup_count(&self) -> usize { - let mut backup_count = self.backup_count.unwrap_or(10u32) as usize; - if backup_count < 1_usize { - backup_count = 1_usize; - } else if backup_count > 10000_usize { - backup_count = 10000_usize; - } - backup_count + min( + max(self.backup_count.unwrap_or(10u32) as usize, 1_usize), + 1000_usize + ) } } @@ -133,7 +131,7 @@ pub fn remove_start_end_slash(s: &str) -> String { while ss.ends_with("/") { ss = &ss[0..(ss.len() - 1)]; } - ss.to_string() + ss.to_owned() } pub fn parse_config(config_json: &json::JsonValue) -> OSSBackupdConfig {