mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-04 22:52:23 +08:00
refactor(profile): improve error handling for file not found case
refactor(merge): simplify deep_merge function signature chore: remove unused fmt_bytes function and related tests chore: clean up help module by removing unused macros chore: remove format module from utils
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
/// Format bytes into human readable string (B, KB, MB, GB)
|
||||
#[allow(unused)]
|
||||
pub fn fmt_bytes(bytes: u64) -> String {
|
||||
const UNITS: &[&str] = &["B", "KB", "MB", "GB"];
|
||||
let (mut val, mut unit) = (bytes as f64, 0);
|
||||
while val >= 1024.0 && unit < 3 {
|
||||
val /= 1024.0;
|
||||
unit += 1;
|
||||
}
|
||||
format!("{:.1}{}", val, UNITS[unit])
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_fmt_bytes() {
|
||||
assert_eq!(fmt_bytes(0), "0.0B");
|
||||
assert_eq!(fmt_bytes(512), "512.0B");
|
||||
assert_eq!(fmt_bytes(1024), "1.0KB");
|
||||
assert_eq!(fmt_bytes(1536), "1.5KB");
|
||||
assert_eq!(fmt_bytes(1024 * 1024), "1.0MB");
|
||||
assert_eq!(fmt_bytes(1024 * 1024 * 1024), "1.0GB");
|
||||
}
|
||||
}
|
||||
@@ -134,18 +134,3 @@ pub fn linux_elevator() -> String {
|
||||
Err(_) => "sudo".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// return the string literal error
|
||||
#[macro_export]
|
||||
macro_rules! ret_err {
|
||||
($str: expr) => {
|
||||
return Err($str.into())
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! t {
|
||||
($en:expr, $zh:expr, $use_zh:expr) => {
|
||||
if $use_zh { $zh } else { $en }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
pub mod dirs;
|
||||
pub mod format;
|
||||
pub mod help;
|
||||
pub mod i18n;
|
||||
pub mod init;
|
||||
|
||||
Reference in New Issue
Block a user