1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-29 08:30:04 +08:00

fix clippy

This commit is contained in:
2020-01-11 11:51:28 +08:00
parent c4c6273c38
commit 5074a46c61
3 changed files with 18 additions and 18 deletions

View File

@@ -9,20 +9,20 @@ pub const SIZE_TB: i64 = SIZE_PB * SIZE_KB;
pub fn parse_size(size: &str) -> XResult<i64> {
let lower_size = size.to_lowercase();
let no_last_b_size = if lower_size.ends_with("b") {
let no_last_b_size = if lower_size.ends_with('b') {
&lower_size[0..lower_size.len()-1]
} else {
&lower_size
};
if no_last_b_size.ends_with("k") {
if no_last_b_size.ends_with('k') {
return Ok((SIZE_KB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
} else if no_last_b_size.ends_with("m") {
} else if no_last_b_size.ends_with('m') {
return Ok((SIZE_MB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
} else if no_last_b_size.ends_with("g") {
} else if no_last_b_size.ends_with('g') {
return Ok((SIZE_GB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
} else if no_last_b_size.ends_with("t") {
} else if no_last_b_size.ends_with('t') {
return Ok((SIZE_TB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
} else if no_last_b_size.ends_with("p") {
} else if no_last_b_size.ends_with('p') {
return Ok((SIZE_PB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
}
@@ -31,16 +31,16 @@ pub fn parse_size(size: &str) -> XResult<i64> {
pub fn get_display_size(size: i64) -> String {
if size < SIZE_KB {
return size.to_string();
size.to_string()
} else if size < SIZE_MB {
return format!("{:.*}KB", 2, (size as f64) / 1024.);
format!("{:.*}KB", 2, (size as f64) / 1024.)
} else if size < SIZE_GB {
return format!("{:.*}MB", 2, (size as f64) / 1024. / 1024.);
format!("{:.*}MB", 2, (size as f64) / 1024. / 1024.)
} else if size < SIZE_TB {
return format!("{:.*}GB", 2, (size as f64) / 1024. / 1024. / 1024.);
format!("{:.*}GB", 2, (size as f64) / 1024. / 1024. / 1024.)
} else if size < SIZE_PB {
return format!("{:.*}TB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024.);
format!("{:.*}TB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024.)
} else {
return format!("{:.*}PB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024. / 1024.);
format!("{:.*}PB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024. / 1024.)
}
}